home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Graphics / SMan / MorphOS / Source / SManMOS.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-29  |  59.1 KB  |  2,547 lines

  1. #include    <clib/all_protos.h>
  2. #include    <math.h>
  3. #include    <float.h>
  4. #include    <string.h>
  5. #include    <exec/memory.h>
  6. #include    <exec/tasks.h>
  7. #include    <iffp/packer.h>
  8. #include    <iff/iff.h>
  9. #include    <iff/ilbm.h>
  10. #include    <exec/execbase.h>
  11. #include    <graphics/gfxbase.h>
  12. #include    <devices/timer.h>
  13. #include    <utility/tagitem.h>
  14.  
  15.  
  16. #include    <powerpc/powerpc.h>
  17. #include    <powerpc/tasksPPC.h>
  18. #include    <clib/powerpc_protos.h>
  19.  
  20.  
  21.  
  22. #include    <clib/cybergraphics_protos.h>
  23. #include    <cybergraphx/cybergraphics.h>
  24.  
  25.  
  26. #define SETRGB(s,cn,r,g,b)     SetRGB4(&((s)->ViewPort),cn,r,g,b)
  27.  
  28. double Pi;
  29.  
  30. ULONG Time1Hi,Time2Hi,Time1Lo,Time2Lo;
  31.  
  32. extern void FndFnc(void);
  33. extern void Save(void);
  34.  
  35. extern void    TimeGet(void);
  36. extern void TimeGet2(void);
  37.  
  38. double ClkFrq,BusFrq;
  39.  
  40. LONG TimeHi,TimeLo;
  41.  
  42. extern void UseLibP2(double);
  43. extern void UseLibP3(double);
  44. extern void UseLibP4(double);
  45. extern void UseLibP5(double);
  46. extern void UseLibP6(double);
  47. extern void UseLibP7(double);
  48.  
  49.  
  50. #define MemMode MEMF_FAST | MEMF_CLEAR | MEMF_REVERSE
  51. UWORD *OldColorTable,*NewColorTable;
  52. ULONG    ThisMode,TableSize;
  53. ULONG    BFactor = 16777216;
  54. ULONG ColorsOld[4];
  55. ULONG ColorsNext[4];
  56. ULONG *LPixelBuf;
  57. UBYTE *WindowBuf;
  58.  
  59.  
  60. UWORD *POTGOR;
  61. UBYTE *DDRAV,*SDRV,*PDRAAV;
  62.  
  63.  
  64. struct Library *WarpBase;
  65. struct Library *TimerBase;
  66. struct MsgPort *TimerPort;
  67. struct timerequest *tr;
  68. /*struct TaskPPC *MyTask;*/
  69. struct    Task *MyTask;
  70.  
  71. UBYTE *PixelBuf;
  72. char CPUStrBuf[256];
  73. char MyStringBuf[256];
  74.  
  75. UWORD ShortOld[4];
  76. UWORD ShortNext[4];
  77. UBYTE OldColors[4];
  78. UBYTE NextColors[4];
  79. UBYTE *ColorTable32;
  80.  
  81.  
  82. UWORD    LastMax,Color;
  83. ULONG NumColors,TopCol,Secs,Micros,LSec;
  84. double ElTime;
  85. int    NumPubs,BPP,MWWidth;
  86. int        PalSize;
  87.  
  88. UBYTE *BoardMem;
  89. extern int Selected;
  90. int    TotNum;
  91.  
  92. SHORT    VertPos;
  93. SHORT    PolyTab[10];
  94. SHORT    *PolyPnt;
  95. SHORT    DeltaX,DeltaY; SHORT    x1,y1,x2,y2;
  96. SHORT    Power;
  97. double    PowerF,DeltaP;    /*Fractional power */
  98. double    DX;
  99. struct CyberModeNode *CyberTags;
  100.  
  101. double Two,Limit,XWidth,XHeight,Pi,XCenter,YCenter,HWidth,HHeight,Factor,Pi,TwoPi,PowerN;
  102. double LastX,LastY,LastFactor,PiD2;
  103. LONG    xtemp,ytemp,MaxCnt,CurCnt,XC,YC,LeftEdge,RightEdge,NearEdge,FarEdge;
  104. ULONG    MltPlr;
  105. ULONG    *PlnPtr;
  106. LONG     BLeft,BTop,InfBLeft,InfBTop;
  107. WORD    WWidth,WHeight,WDepth,SDepth,PFMT;
  108. BPTR    FileHandle;
  109. UWORD    FontHeight,MenWidth,LeftPos;
  110. SHORT    TFHeight;
  111. USHORT    IWHeight,IWWidth,TwoSpace;
  112. UWORD    LinBuf[1600];
  113. BOOL IsChunk,IsVilScreen,IsCyberScreen,SaveIFF;
  114.  
  115.  
  116. struct TextAttr        DefBold;
  117. struct    TextAttr    *DefFont;
  118. struct    TextFont    *DFont;
  119. struct    TextFont    *BFont;
  120. struct TextFont *CWFont;
  121.  
  122. struct    TextExtent    TextUsed;
  123.  
  124. struct TextAttr topaz8 =
  125.   {
  126.   (STRPTR)"topaz.font",    /* ta_Name */
  127.   8,    /* ta_YSize */
  128.   FS_NORMAL,    /* ta_Style */
  129.   0x0    /* ta_Flags */
  130.   };
  131.  
  132.  
  133. struct TextAttr topaz9 =
  134.   {
  135.   (STRPTR)"topaz.font",    /* ta_Name */
  136.   9,    /* ta_YSize */
  137.   FSB_BOLD,    /* ta_Style */
  138.   0x0    /* ta_Flags */
  139.   };
  140.  
  141.  
  142. #define    ChdFlg    DefFlg | CHECKIT | CHECKED
  143. #define    ChkFlg    DefFlg | CHECKIT
  144.  
  145. ULONG    CmpFlg    = MOUSEBUTTONS | MENUPICK ;
  146. ULONG    MyFlag     =    NOCAREREFRESH|REPORTMOUSE|BORDERLESS;
  147. ULONG    MenFlg     =    MENUENABLED | MIDRAWN;
  148. ULONG    DefFlg     =    ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP;
  149.  
  150. extern    struct DosLibrary *DOSBase;
  151. struct GfxBase *GfxBase;
  152. struct Library *DiskfontBase;
  153. struct IntuitionBase *IntuitionBase;
  154. struct Library *GadToolsBase;
  155. struct Library *UtilityBase;
  156. struct CyberGfxBase *CyberGfxBase;
  157. struct Library *CyberIntuit;
  158. struct Library *CyberLayer;
  159. struct Library *CgxSystemBase;
  160.  
  161. extern    struct ExecBase    *SysBase;
  162. struct    Gadget    *GadStuff;
  163. struct    NewScreen    ns;
  164. struct    NewWindow    nw;
  165. BYTE    CurrentXOffset;
  166. BYTE    CurrentYOffset;
  167. UBYTE    Title[] = " Information about this Fractal";
  168. UBYTE    TitleM[] = "  Exploring the Julia Sets";
  169.  
  170. UBYTE    *WindowName;
  171. SHORT    SWidth,SHeight,CPU;
  172. USHORT    MyView,SysFlag,MenVal;
  173. ULONG    IMClass;
  174. struct    Screen    *WBScreen;
  175. struct    Window    *InfoWindow;
  176. struct    Window    *IntWindow;
  177.  
  178. struct    MsgPort    *MyPort,*IntPort,*MWPort;
  179. struct    RastPort    *WBRast,*CWRast,*MWRast,*WBSRast;
  180. struct    ViewPort    VPorta,VPortb;
  181. struct    Preferences    MyNewPrefs,*CurPrefs;
  182. struct    Menu        ProjMenu,CountMenu,ChangeMenu,PowerMenu;
  183. struct    MenuItem    *MIStruct;
  184. struct    IntuiText    *ITStruct;
  185.  
  186. /*    The following structures are for temporary non-displayable rastors for use in
  187. saving the image to an iff file */
  188. struct RastPort VTmpRast,MainWRast;
  189. struct BitMap *TmpBitMap,*MWBitMap;
  190. struct BitMap *NWBitMap;
  191. struct RastPort NWRast;
  192.  
  193.  
  194. struct    MenuItem    MI11,MI12,MI13,MI14,MI15,MI16,MI17;
  195. struct    MenuItem    MI31,MI32,MI33,MI34,MI35,MI36;
  196. struct    MenuItem    MI41,MI42,MI43,MI44,MI45,MI46,MI47;
  197. struct    MenuItem    MI21,MI22,MI23,MI24,MI25,MI26;
  198. struct    IntuiText    IT11,IT12,IT13,IT14,IT15,IT16,IT17;
  199. struct    IntuiText    IT31,IT32,IT33,IT34,IT35,IT36;
  200. struct    IntuiText    IT41,IT42,IT43,IT44,IT45,IT46,IT47;
  201. struct    IntuiText    IT21,IT22,IT23,IT24,IT25,IT26;
  202. struct    IntuiText    DummyText;
  203.  
  204. struct    PLANEPTR    *PlanePtrA;
  205. UBYTE    PalOpt;
  206. UBYTE    Comma[] = {0x2c};
  207. static    char    Mesag3[]    = "System Hardware: ";
  208. static    char    Mesag4[]    = "Use the menu options on the Julia Window to change the following parameters!";
  209. static    char    Mesag5[]    = "Click on the Close Gadget to bring the Julia Window forward!";
  210. static    char    Mesag6[]    = "(Note:  This window won't be closed, but perhaps hidden.)";
  211. static    char    Mesag7[]    = "To bring the Information Window forward, select 'About' from the Project menu!";
  212. static    char    Mesag8[]    = "The Window 'Exploring the Juila Sets' is on the screen                       ";
  213. static    char    ScrMsg[]    = "Window center is at ";
  214. static    char    MandMsg[]    = "The algorithm is z  + z -> z, where z = x + iy.";
  215. static    char    MandMsgG[]    = "The algorithm is z   + z -> z, where z = x + iy.";
  216. static    char    MandMsgP[]    = "The algorithm is z                 + z -> z, where z = R*exp(i0).";
  217. static    char    MandMsgPG[]    = "The algorithm is z                  + z -> z, where z = R*exp(i0).";
  218. static    char    ChpMsg[]    = "Chip Memory Free = ";
  219. static    char    ChpEnd[]    = "                ";
  220. static    char    FstMsg[]    = "Fast Memory Free = ";
  221. static    char    FstEnd[]    = "                        ";
  222. static    char    WdtMsg[]    = "Image Width =  ";
  223. static    char    WdtEnd[]    = "        ";
  224. static    char    HgtMsg[]    = "Image Height = ";
  225. static    char    HgtEnd[]    = "        ";
  226. static    char    MagMsg[]    = "Magnification =               ";
  227. static    char    XPos[]        = "x = ";
  228. static    char    XPsEnd[]    = "                              ";
  229. static    char    YPos[]        = "y = ";
  230. static    char    YPsEnd[]    = "                              ";
  231. static    char    CntMsg[]    = "Maximum Count = ";
  232. static    char    CntEnd[]    = "             ";
  233. static    char    St882[]        = " 68882";
  234.  
  235. extern void FncFnd(double);
  236.  
  237.  
  238. WORD GetLength(UBYTE *);
  239. WORD GethPos(UBYTE *);
  240. WORD LengthDescript(void);
  241. void InitVS(void);
  242. void LibsOpen(void);
  243. void TrueToggle(UWORD,UWORD,UWORD,UWORD);
  244. void LibsClose(void);
  245. void LineToggle(UWORD,UWORD,UWORD,UWORD);
  246. void WriteStuff(void);
  247. void WindowSet(void);
  248. void CheckMsg(void);
  249. void CheckIntMsg(void);
  250. void ITInit(struct IntuiText *,UBYTE *);
  251. void ErrorDisplay(void);
  252. void MIInit(struct MenuItem *,struct MenuItem *,SHORT,BYTE,APTR,SHORT);
  253. void CheckCOPP(void);
  254. void MenuInit(struct Menu *,struct Menu *,BYTE *,SHORT,SHORT);
  255. void PowerChange(void);
  256. void MyFill(UWORD,UWORD,UWORD,UWORD,UWORD);
  257. void DescribeSystem(void);
  258. void ScreenSet(void);
  259. void CountChange(void);
  260. void ScreenClose(void);
  261. void Palette32(void);
  262. void ScreensClose(void);
  263. void GetWindowSize(void);
  264. int  OpenWrite(UBYTE *);
  265. void FullSurface(void);
  266. void FullSurface2(void);
  267. void FullSurface3(void);
  268.  
  269. int  WriteFile(UBYTE *,ULONG);
  270. void Status(void);
  271. void CloseWrite(void);
  272. void RestoreOrigColors(void);
  273. int ShowPalette(void);
  274. UBYTE *GetColors(UBYTE *,ULONG);
  275. ULONG LongSwap(ULONG);
  276. void MySetRGB(SHORT,USHORT);
  277.  
  278. void StorePalette(UBYTE *);
  279.  
  280. void DisLine(struct RastPort *,char *,int);
  281.  
  282. struct timeval CurTime;
  283.  
  284.  
  285. void InitVS(void)
  286. {
  287.     BPP = GetCyberIDAttr(CYBRIDATTR_BPPIX,ThisMode);
  288.  
  289.     SDepth = GetCyberIDAttr(CYBRIDATTR_DEPTH,ThisMode);
  290.     SWidth = GetCyberIDAttr(CYBRIDATTR_WIDTH,ThisMode);
  291.     SHeight = GetCyberIDAttr(CYBRIDATTR_HEIGHT,ThisMode);
  292.     PFMT = GetCyberIDAttr(CYBRIDATTR_PIXFMT,ThisMode);
  293. }
  294.  
  295.  
  296. struct timerequest *CreateTimer(ULONG unit)
  297. {
  298. LONG error;
  299. struct timerequest *TimerMsg;
  300.  
  301.     TimerPort = CreatePort("MyTimer",32);
  302.     TimerMsg = (struct timerequest *)    CreateIORequest(TimerPort,sizeof(struct timerequest ));
  303.     if (!TimerMsg) return(NULL);
  304.     error = OpenDevice("timer.device",UNIT_MICROHZ,(struct IORequest *) TimerMsg,0L);
  305.     if (error)    {
  306.         DeletePort(TimerPort);
  307.         return(NULL);
  308.         }
  309.     return(TimerMsg);
  310. }
  311.  
  312.  
  313. void OpenTimer(void)
  314. {
  315.     tr = CreateTimer(1);
  316.     TimerBase = (struct Library *)tr->tr_node.io_Device;
  317. }
  318.  
  319. void CloseTimer(void)
  320. {
  321.     if (TimerPort) DeletePort(TimerPort);
  322.     if (TimerBase) TimerBase = (struct Library *)(-1);
  323. }
  324.  
  325.  
  326. void TrueToggle(x,y,xe,ye)
  327. UWORD x, y, xe, ye;
  328. {
  329. ULONG tmpVal;
  330. ULONG color;
  331. UWORD Lft,Top;
  332.     Lft = IntWindow->LeftEdge;
  333.     Top = IntWindow->TopEdge;
  334.     if (y > ye)    {
  335.         tmpVal = y;
  336.         y = ye;
  337.         ye = tmpVal;
  338.         }
  339.     if (y == ye)    {
  340.         if (x > xe) {
  341.             tmpVal = x;
  342.             x = xe;
  343.             xe = tmpVal;
  344.             }
  345.         while(x < xe) {
  346.             color = ReadRGBPixel(&WBScreen->RastPort,x + Lft,y + Top);
  347.             color = 0xffffff - color;
  348.             color = color & 0xffffff;
  349.             WriteRGBPixel(&WBScreen->RastPort,x+Lft,y+Top,color);
  350.             x++;
  351.             }
  352.         }
  353.     else while (y < ye)    {
  354.         color = 0xffffff - ReadRGBPixel(&WBScreen->RastPort,x + Lft,y + Top);
  355.         color = color & 0xffffff;
  356.         WriteRGBPixel(&WBScreen->RastPort,x+Lft,y+Top,color);
  357.         y++;
  358.         }
  359. }
  360.  
  361. void LineToggle(x,y,xe,ye)
  362. UWORD x, y, xe, ye;
  363. {
  364. UWORD tmpVal;
  365. UBYTE color;
  366.     if (SDepth > 8)    {
  367.         TrueToggle(x,y,xe,ye);
  368.         return;
  369.         }
  370.     if (y > ye)    {
  371.         tmpVal = y;
  372.         y = ye;
  373.         ye = tmpVal;
  374.         }
  375.     if (y == ye)    {
  376.         if (x > xe) {
  377.             tmpVal = x;
  378.             x = xe;
  379.             xe = tmpVal;
  380.             }
  381.         while(x < xe) {
  382.             color = ReadPixel(CWRast,x,y);
  383.             color = 255 - color;
  384.             SetAPen(CWRast,color);
  385.             WritePixel(CWRast,x,y);
  386.             x++;
  387.             }
  388.         }
  389.     else while (y < ye)    {
  390.         color = 255 - ReadPixel(CWRast,x,y);
  391.         SetAPen(CWRast,color);
  392.         WritePixel(CWRast,x,y);
  393.         y++;
  394.         }
  395. }
  396.  
  397. void TruePixel(UWORD x,UWORD y,ULONG color)
  398. {
  399. ULONG *DstBuf,*Src;
  400.     DstBuf = (ULONG *)WindowBuf;
  401.     DstBuf = DstBuf + WWidth*(ULONG)y;
  402.     DstBuf = DstBuf + (ULONG)x;
  403.     Src = (ULONG *)ColorTable32 + color;
  404.     *DstBuf = *Src;
  405. }
  406.  
  407. void SetTrueColor(UWORD x, UWORD y, ULONG color)
  408. {
  409. ULONG *ColLng;
  410. UWORD Lft,Top;
  411. UBYTE *Src;
  412.     Lft = IntWindow->LeftEdge;
  413.     Top = IntWindow->TopEdge;
  414.     Lft = Lft + BLeft;
  415.     Top = Top + BTop;
  416.     if (x  + BLeft >= IntWindow->Width - IntWindow->BorderRight) return;
  417.     if (color < 0xfffe)    color = color + 4;
  418.     Src = ColorTable32 + 4*color;
  419.     ColLng = (ULONG *)Src;
  420.     *LPixelBuf++ = *ColLng;
  421. }
  422.  
  423. void ReadPackedLine(struct Screen *s,UWORD xs,UWORD y,UWORD lWidth,UBYTE *Dest)
  424. {
  425. UWORD pCnt;
  426.     register ULONG    offset = (s->Width*y + xs);
  427.     pCnt = 0;
  428.     while (pCnt < lWidth)    {
  429.         *Dest++ = *(BoardMem+offset);
  430.         offset++;
  431.         pCnt++;
  432.     }
  433. }
  434.  
  435. void ITInit(Item,NamePtr)
  436. struct    IntuiText    *Item;
  437. UBYTE    *NamePtr;
  438. {
  439.     Item -> IText = NamePtr;
  440.     Item -> BackPen = 0;
  441.     Item -> FrontPen = 3;
  442.     Item -> DrawMode = JAM1;
  443. }
  444.  
  445. void MIInit(Item,NxtItem,TEdge,Cmd,ITItem,Width)
  446. struct    MenuItem    *Item,*NxtItem;
  447. APTR    ITItem;
  448. SHORT    TEdge,Width;
  449. BYTE    Cmd;
  450. {
  451.     Item -> Command = Cmd;
  452.     Item -> TopEdge = TEdge;
  453.     Item -> NextItem = NxtItem;
  454.     Item -> ItemFill = (APTR)ITItem;
  455.     Item -> Flags = (USHORT)DefFlg;
  456.     Item -> Height = FontHeight;
  457.     Item -> Width = Width;
  458. }
  459.  
  460. void MenuInit(MenuStruct,NxtMenu,NamePtr,LEdge,MWidth)
  461. struct Menu    *MenuStruct,*NxtMenu;
  462. SHORT    LEdge,MWidth;
  463. BYTE    *NamePtr;
  464. {
  465.     MenuStruct -> NextMenu = NxtMenu;
  466.     MenuStruct -> Width = MWidth;
  467.     MenuStruct -> Height = FontHeight;    /*9;*/
  468.     MenuStruct -> LeftEdge = LEdge;
  469.     MenuStruct -> TopEdge = 0;
  470.     MenuStruct -> MenuName = NamePtr;
  471.     MenuStruct -> Flags = MenFlg;
  472.  
  473. }
  474.  
  475.  
  476. void MyFill(color,xl,yt,xr,yb)
  477. UWORD color,xl,yt,xr,yb;
  478. {
  479. UWORD x,y;
  480.     x = xl;
  481.     y = yt;
  482.     while (y < yb) {
  483.         while (x < xr) {
  484.             TruePixel(x,y,(ULONG)color);
  485.             x++;
  486.             }
  487.         x = xl;
  488.         y++;
  489.         }
  490. }
  491.  
  492.  
  493. ULONG    LngColor(int TableCnt)
  494. {
  495. ULONG RGBColor;
  496. UBYTE *Src;
  497. UBYTE Red, Green, Blue;
  498.     Src = (UBYTE *)NewColorTable;
  499.     Src = Src + 4*TableCnt;
  500.     Blue = *Src++;
  501.     Green = *Src++;
  502.     Red = *Src++;
  503.     RGBColor = (ULONG)Red;
  504.     RGBColor <<= 8;
  505.     RGBColor = RGBColor | (ULONG)Green;
  506.     RGBColor <<= 8;
  507.     RGBColor = RGBColor | (ULONG)Blue;
  508.     return(RGBColor);
  509.  
  510. }
  511.  
  512. int ShowPicPalette(void)
  513. {
  514. int TmpCol,TopCol;
  515. UWORD xPos,yPos,deltaX,deltaY;
  516.     if (BPP == 1)    {
  517.         yPos = ShowPalette();
  518.         return(yPos);
  519.     }
  520.     deltaX = 4;
  521.     deltaY = 4;
  522.     TmpCol = 0;
  523.     xPos = 20;
  524.     yPos = 2;
  525.     if (BPP == 1) TopCol = 256;
  526.     else TopCol = 3*4096;
  527.     TmpCol = 0;
  528.     while ((TmpCol < TopCol)&&(yPos+20 < IntWindow->Height))    {
  529.         MyFill((UWORD)TmpCol,xPos,yPos,xPos+deltaX,yPos+deltaY);
  530.         xPos = xPos + deltaX;
  531.         TmpCol = TmpCol + 2;
  532.         if (xPos+40 > IntWindow->Width)    {
  533.             xPos = 20;
  534.             yPos = yPos + deltaY;
  535.             }
  536.         }
  537.     return((int)yPos);
  538. }
  539.  
  540. ShowPalette(void)
  541. {
  542. int TmpCol;
  543. UWORD xPos,yPos,deltaX,deltaY;
  544.     deltaX = 16;
  545.     deltaY = 16;
  546.     TmpCol = 4;
  547.     if (NumColors == 16) {
  548.         TmpCol = 0;
  549.         }
  550.     xPos = BLeft;
  551.     yPos = BTop;
  552.     while (TmpCol < TopCol)    {
  553.         SetAPen(CWRast,TmpCol);
  554.         RectFill(CWRast,xPos,yPos,xPos+deltaX,yPos+deltaY);
  555.         if (xPos > WWidth - 80)    {
  556.             xPos = BLeft - deltaX;
  557.             yPos = yPos + deltaY;
  558.             yPos++;
  559.             }
  560.         xPos = xPos + deltaX;
  561.         TmpCol++;
  562.         if (TmpCol == 17) TmpCol = 20;
  563.         }
  564.         SetAPen(CWRast,TmpCol);
  565.         RectFill(CWRast,xPos,yPos,xPos+deltaX,yPos+deltaY);
  566.     return(yPos);
  567. }
  568.  
  569. void ScreenSet()
  570. {
  571. WORD    xPos,yPos;
  572. nw.Title = &TitleM[0];
  573. nw.LeftEdge        =    0;
  574. nw.TopEdge        =    0;
  575.  
  576. nw.Width        =    600;
  577. nw.Height        =    400;
  578.  
  579. nw.Width        =    534;
  580. nw.Height        =    400;
  581.  
  582. nw.Width        =    345;
  583. nw.Height        =    272;
  584.  
  585. nw.BlockPen        =    WBScreen->BlockPen;
  586. nw.DetailPen    =    WBScreen->DetailPen;
  587. nw.IDCMPFlags    =    CmpFlg | IDCMP_NEWSIZE | CLOSEWINDOW ;
  588. nw.Flags        =    WINDOWDRAG|WINDOWDEPTH|SMART_REFRESH|WINDOWCLOSE|ACTIVATE|REPORTMOUSE | WFLG_NEWLOOKMENUS | WFLG_SIZEGADGET;
  589. nw.Screen        =     WBScreen;
  590. nw.FirstGadget    =    NULL;
  591. nw.CheckMark    =    NULL;
  592. nw.BitMap        =    NULL;
  593. nw.MinWidth        =    100;
  594. nw.MinHeight    =    75;
  595. nw.MaxWidth        =    WBScreen->Width;
  596. nw.MaxHeight    =    WBScreen->Height;
  597.  
  598.     if (NumColors == 16)    PalSize = 16;
  599.     else PalSize = TopCol - 6;
  600.     if ((WBScreen->Width < 400)||(WBScreen->Height < 300))    {
  601.         nw.Width        =    WBScreen->Width;
  602.         nw.Height        =    WBScreen->Height;
  603.     }
  604.     IntWindow = (struct Window *)OpenWindow( &nw );
  605.     BLeft = (LONG)IntWindow->BorderLeft;
  606.     BTop = (LONG)IntWindow->BorderTop;
  607.     RightEdge = IntWindow->GZZWidth;
  608.     FarEdge = IntWindow->GZZHeight;
  609.     WWidth = RightEdge;
  610.     WHeight = FarEdge;
  611.     XC = RightEdge/2;
  612.     YC = FarEdge/2;
  613. /* Get associated information about Int window */
  614.     CWRast = IntWindow -> RPort;
  615.     IntPort    = IntWindow -> UserPort;
  616.     MWPort    = IntWindow -> UserPort;
  617.     xPos = BLeft;
  618.     yPos = BTop;
  619.     DummyText.ITextFont = DefFont;
  620.     DummyText.IText = (UBYTE *)"Project__";
  621.     MenWidth = IntuiTextLength(&DummyText);
  622.  
  623.  
  624.     MenuInit(&ProjMenu,&CountMenu,"Project",20,MenWidth);
  625.     DummyText.IText = (UBYTE *)"Redraw(Same P)___________";
  626.     MenWidth = IntuiTextLength(&DummyText);
  627.     ProjMenu.FirstItem = &MI11;
  628.     MIInit(&MI11,&MI12,0,0x41,&IT11,MenWidth);
  629.     MIInit(&MI12,&MI13,FontHeight,0x50,&IT12,MenWidth);
  630.     MIInit(&MI13,&MI14,2*FontHeight,0x53,&IT13,MenWidth);
  631.     MIInit(&MI14,&MI15,3*FontHeight,0x49,&IT14,MenWidth);
  632.     MIInit(&MI15,&MI16,4*FontHeight,0x4c,&IT15,MenWidth);
  633.     MIInit(&MI16,&MI17,5*FontHeight,0x4e,&IT16,MenWidth);
  634.     MIInit(&MI17,0,6*FontHeight,0x51,&IT17,MenWidth);
  635.  
  636.     ITInit(&IT11,"About");
  637.     ITInit(&IT12,"Redraw(Same P)");
  638.     ITInit(&IT13,"Save Image (bmp)");
  639.     ITInit(&IT14,"Save Image (iff)");
  640.     ITInit(&IT15,"Save Parm");
  641.     ITInit(&IT16,"Load Parm");
  642.     ITInit(&IT17,"Quit");
  643.     LeftPos = MenWidth;
  644.     DummyText.IText = (UBYTE *)"Maximum Count__";
  645.     MenWidth = IntuiTextLength(&DummyText);
  646.  
  647.     MenuInit(&CountMenu,&ChangeMenu,"Maximum Count",LeftPos,MenWidth);
  648.     DummyText.IText = (UBYTE *)"Decrease by 8_________";
  649.     MenWidth = IntuiTextLength(&DummyText);
  650.  
  651.     CountMenu.FirstItem = &MI31;
  652.     MIInit(&MI31,&MI32,0,43,&IT31,MenWidth);
  653.     MIInit(&MI32,&MI33,FontHeight,45,&IT32,MenWidth);
  654.     MIInit(&MI33,&MI34,2*FontHeight,0x44,&IT33,MenWidth);
  655.     MIInit(&MI34,0,3*FontHeight,0x48,&IT34,MenWidth);
  656.  
  657.     ITInit(&IT31,"Increase by 8");
  658.     ITInit(&IT32,"Decrease by 8");
  659.     ITInit(&IT33,"Double");
  660.     ITInit(&IT34,"Halve");
  661.  
  662.     LeftPos = LeftPos + MenWidth;
  663.     DummyText.IText = (UBYTE *)"Changes___";
  664.     MenWidth = IntuiTextLength(&DummyText);
  665.  
  666.     MenuInit(&ChangeMenu,&PowerMenu,"Changes",LeftPos,MenWidth);
  667.     DummyText.IText = (UBYTE *)"Power down_________";
  668.     MenWidth = IntuiTextLength(&DummyText);
  669.  
  670.     ChangeMenu.FirstItem = &MI41;
  671.     MIInit(&MI41,&MI42,0,0x5a,&IT41,MenWidth);
  672.     MIInit(&MI42,&MI43,FontHeight,0x52,&IT42,MenWidth);
  673.     MIInit(&MI43,&MI44,2*FontHeight,0x3e,&IT43,MenWidth);
  674.     MIInit(&MI44,&MI45,3*FontHeight,0x3c,&IT44,MenWidth);
  675.     MIInit(&MI45,&MI46,4*FontHeight,0x55,&IT45,MenWidth);
  676.     MIInit(&MI46,&MI47,5*FontHeight,0x45,&IT46,MenWidth);
  677.     MIInit(&MI47,0,6*FontHeight,0x59,&IT47,MenWidth);
  678.  
  679.     ITInit(&IT41,"Zoom");
  680.     ITInit(&IT42,"Restore");
  681.     ITInit(&IT43,"Power Down");
  682.     ITInit(&IT44,"Power Up");
  683.     ITInit(&IT45,"Magnify");
  684.     ITInit(&IT46,"Reduce");
  685.     ITInit(&IT47,"Palette");
  686.  
  687.     LeftPos = LeftPos + MenWidth;
  688.     DummyText.IText = (UBYTE *)"Fractional Power_____";
  689.     MenWidth = IntuiTextLength(&DummyText);
  690.  
  691.     MenuInit(&PowerMenu,0,"Fractional Power",LeftPos,MenWidth);
  692.     DummyText.IText = (UBYTE *)"Multiply increment size by 10_________";
  693.     MenWidth = IntuiTextLength(&DummyText);
  694.  
  695.     PowerMenu.FirstItem = &MI21;
  696.     MIInit(&MI21,&MI22,0,0x2e,&IT21,MenWidth);
  697.     MIInit(&MI22,&MI23,FontHeight,0x30,&IT22,MenWidth);
  698.     MIInit(&MI23,&MI24,2*FontHeight,0x2f,&IT23,MenWidth);
  699.     MIInit(&MI24,&MI25,3*FontHeight,0x78,&IT24,MenWidth);
  700.     MIInit(&MI25,&MI26,4*FontHeight,0x5e,&IT25,MenWidth);
  701.     MIInit(&MI26,0,5*FontHeight,0x5c,&IT26,MenWidth);
  702.  
  703.     ITInit(&IT21,"Set Increment Size to 0.1");
  704.     ITInit(&IT22,"Set Increment Size to 0");
  705.     ITInit(&IT23,"Divide Increment Size by 10");
  706.     ITInit(&IT24,"Multiply Increment Size by 10");
  707.     ITInit(&IT25,"Increment Fraction by Size");
  708.     ITInit(&IT26,"Decrement Fraction by Size");
  709.  
  710.     SetMenuStrip(IntWindow,&ProjMenu);
  711.     MenVal = 0;;
  712. }
  713.  
  714. void ScreensClose()
  715. {
  716.     if(InfoWindow) {
  717.         CloseWindow(InfoWindow);
  718.         InfoWindow = 0;
  719.         }
  720.     if(IntWindow) ClearMenuStrip(IntWindow);
  721.     if(IntWindow) {
  722.         CloseWindow(IntWindow);
  723.         IntWindow = 0;
  724.         }
  725. }
  726.  
  727.  
  728. int OpenWrite(UBYTE *FilNam)
  729. {
  730.     FileHandle = Open(FilNam,MODE_NEWFILE);
  731.     if (!FileHandle)    return(-1);
  732.     return(0);
  733. }
  734.  
  735. int WriteFile(UBYTE *Source,ULONG FileLength)
  736. {
  737.     Write(FileHandle,(char *)Source,FileLength);
  738.     return(0);
  739. }
  740. void CloseWrite()
  741. {
  742.     Close(FileHandle);
  743. }
  744.  
  745. UBYTE *GetColors(MyColors,CTSize)
  746. UBYTE *MyColors;
  747. ULONG CTSize;
  748. {
  749. USHORT *CurrentColor,Red,Green,Blue,TCol;
  750.     CurrentColor = WBScreen->ViewPort.ColorMap->ColorTable;
  751.     while (CTSize)    {
  752.         Red = *CurrentColor;
  753.         Red = 0xf00 & Red;
  754.         Red >>= 4;
  755.         TCol = Red;
  756.         TCol >>= 4;
  757.         Red = Red | TCol;
  758.         *MyColors++ = (UBYTE)Red;
  759.         Green = *CurrentColor;
  760.         Green = 0xf0 & Green;
  761.         TCol = Green;
  762.         TCol >>= 4;
  763.         Green = Green | TCol;
  764.         *MyColors++ = (UBYTE)Green;
  765.         Blue = *CurrentColor++;
  766.         Blue = 0xf & Blue;
  767.         TCol = Blue;
  768.         Blue <<= 4;
  769.         Blue = Blue | TCol;
  770.         *MyColors++ = (UBYTE)Blue;
  771.         --CTSize;
  772.         }
  773.     return(MyColors);
  774. }
  775.  
  776. ULONG LongSwap(LngWrd)
  777. ULONG LngWrd;
  778. {
  779. ULONG LngBuf[1];
  780. UBYTE *ByteBuf;
  781. UBYTE Byte1,Byte2,Byte3,Byte4;
  782.     LngBuf[0] = LngWrd;
  783.     ByteBuf = (UBYTE *)LngBuf;
  784.     Byte1 = *ByteBuf++;
  785.     Byte2 = *ByteBuf++;
  786.     Byte3 = *ByteBuf++;
  787.     Byte4 = *ByteBuf;
  788.     ByteBuf = (UBYTE *)LngBuf;
  789.     *ByteBuf++ = Byte4;
  790.     *ByteBuf++ = Byte3;
  791.     *ByteBuf++ = Byte2;
  792.     *ByteBuf = Byte1;
  793.     LngWrd = LngBuf[0];
  794.     return(LngWrd);
  795. }
  796.  
  797. void StorePalette(PalPointer)
  798. UBYTE *PalPointer;
  799. {
  800. UBYTE *TabLoc;
  801. int TableCnt;
  802. UBYTE r,g,b,h,LNib,HNib;
  803.  
  804.     TableCnt = 0;
  805.     TabLoc = (UBYTE *)NewColorTable;
  806.     while (TableCnt < 0x100)    {
  807.         LNib = *TabLoc++;
  808.         HNib = LNib & 0xf0;
  809.         h = HNib;
  810.         h >>= 4;
  811.         h = h | HNib;
  812.         HNib = LNib & 0xf;
  813.         r = HNib;
  814.         r <<= 4;
  815.         r = r | HNib;
  816.         LNib = *TabLoc++;
  817.         HNib = LNib & 0xf0;
  818.         g = HNib;
  819.         g >>= 4;
  820.         g = g | HNib;
  821.         HNib = LNib & 0xf;
  822.         b = HNib;
  823.         b <<= 4;
  824.         b = b | HNib;
  825.         *PalPointer++ = b;
  826.         *PalPointer++ = g;
  827.         *PalPointer++ = r;
  828.         *PalPointer++ = h;
  829.         TableCnt++;
  830.         }
  831.  
  832. }
  833.  
  834. void ChangeNW(void)
  835. {
  836.     nw.Width = 180;
  837.     nw.Height = 40;
  838.     nw.LeftEdge = IntWindow->LeftEdge + 40;
  839.     nw.TopEdge = IntWindow->TopEdge + 40;
  840.     nw.Title = "           Saving";
  841.     nw.IDCMPFlags    =    CmpFlg;
  842.     nw.Flags        =    SMART_REFRESH|ACTIVATE;
  843.  }
  844.  
  845. void DisLine(LineRP,LinMes,LineNum)
  846. struct RastPort *LineRP;
  847. char *LinMes;
  848. int LineNum;
  849. {
  850.         SetAPen(LineRP,0);
  851.         RectFill(LineRP,15,20,130,35);
  852.         SetAPen(LineRP,1);
  853.         Move(LineRP,20,25);
  854.         sprintf(&MyStringBuf[0],LinMes);
  855.         sprintf(&MyStringBuf[strlen(MyStringBuf)],"%d.",(int)(WHeight-LineNum));
  856.         Text(LineRP,&MyStringBuf[0],strlen(MyStringBuf)-1);
  857. }
  858.  
  859. void SaveBMP(void)
  860. {
  861. UBYTE *BMPHdrBuffer;
  862.  
  863. UBYTE *LineBuff;
  864. UBYTE *BMPBodyBuffer;
  865. ULONG *BMPLPointer;
  866. UWORD *BMPWPointer;
  867. struct Window *SavingWnd;
  868. ULONG BMPBodyLength,BPPix;
  869. UWORD WAHL,WAHH;
  870. BPTR BMHandle;
  871. LONG PixCount;
  872.  
  873. UWORD LBufLength,LinePos,DstMode;
  874. int LineNum,HdrSize,WDepth;
  875. char *FilNam;
  876. UBYTE r,g,b;
  877.  
  878.     WDepth = IntWindow->RPort->BitMap->Depth;
  879.     if (BPP == 1) {
  880.         HdrSize = 0x436;
  881.         FilNam = "Mand8.bmp";
  882.         WAHL = WWidth;
  883.         BPPix = 0x00080001;
  884.         if (WDepth == 4) FilNam = "Mand4.bmp";
  885.         if (WDepth == 5) FilNam = "Mand5.bmp";
  886.         }
  887.     else {
  888.         HdrSize = 0x36;
  889.         FilNam = "Mand.bmp";
  890.         WAHL = 3*WWidth;
  891.         BPPix = 0x00180001;
  892.         }
  893.     BMPHdrBuffer = AllocMem(HdrSize,MemMode);
  894.     BMPWPointer = (UWORD *)BMPHdrBuffer;
  895.     *BMPWPointer++ = 0x424d;    /* 'BM' */
  896.     BMPLPointer = (ULONG *)BMPWPointer;
  897.     WAHH = WAHL;
  898.     WAHL >>= 2;  /* Divide by 4 */
  899.     WAHL <<= 2;  /* Multiply by 4 */
  900.     while (WAHH - WAHL) {
  901.         WAHH++;
  902.         WAHL = WAHH;
  903.         WAHL >>= 2;
  904.         WAHL <<= 2;
  905.         }
  906.     WAHL = WAHH;
  907.     LBufLength = WAHH;
  908.     LineBuff = AllocMem(LBufLength+4,MemMode);
  909.     BMPBodyLength = WAHH*WHeight;
  910.     *BMPLPointer++ = LongSwap(BMPBodyLength + HdrSize);
  911.     *BMPLPointer++ = 0;
  912.     *BMPLPointer++ = LongSwap(HdrSize);    /* 0x36 or 0x436 bytes of header.*/
  913.     *BMPLPointer++ = LongSwap(0x28);    /* 0x28 = 40 bytes remaining before palette (if any).*/
  914.     *BMPLPointer++ = LongSwap((ULONG)WWidth);
  915.     *BMPLPointer++ = LongSwap((ULONG)WHeight);
  916.     *BMPLPointer++ = LongSwap(BPPix);
  917.     *BMPLPointer++ = 0;
  918.     *BMPLPointer++ = LongSwap(BMPBodyLength);
  919.     *BMPLPointer++ = 0;
  920.     *BMPLPointer++ = 0;
  921.     *BMPLPointer++ = 0;
  922.     *BMPLPointer++ = 0;
  923.     if (BPP == 1) StorePalette((UBYTE *)BMPLPointer);
  924.     LineNum = WHeight - 1;
  925.     ChangeNW();
  926.     SavingWnd = OpenWindow(&nw);
  927.     BMHandle = Open(FilNam,MODE_NEWFILE);
  928.     Write(BMHandle,BMPHdrBuffer,HdrSize);
  929.     DstMode = (UWORD)(3*WWidth);
  930.     SetFont(SavingWnd->RPort,CWFont);
  931.     while (LineNum >= 0)    {
  932.         BMPBodyBuffer = LineBuff + LBufLength - 1;
  933.         *BMPBodyBuffer-- = 0;
  934.         *BMPBodyBuffer-- = 0;
  935.         *BMPBodyBuffer-- = 0;
  936.         *BMPBodyBuffer = 0;
  937.         LinePos = (UWORD)IntWindow->BorderTop + (UWORD)LineNum;
  938.         if (BPP == 1)    {
  939.             ReadPixelLine8(IntWindow->RPort,IntWindow->BorderLeft,LinePos,WWidth,LineBuff,&MainWRast);
  940.             }
  941.         else    {
  942.             PixCount = ReadPixelArray((APTR*)LineBuff,0,0,DstMode,IntWindow->RPort,IntWindow->BorderLeft,LinePos,(UWORD)WWidth,1,RECTFMT_RGB);
  943.             PixCount = WWidth;
  944.             BMPBodyBuffer = LineBuff;
  945.             while (PixCount)    {
  946.                 r = *BMPBodyBuffer++;
  947.                 g = *BMPBodyBuffer++;
  948.                 b = *BMPBodyBuffer;
  949.                 --BMPBodyBuffer;
  950.                 --BMPBodyBuffer;
  951.                 *BMPBodyBuffer++ = b;
  952.                 *BMPBodyBuffer++ = g;
  953.                 *BMPBodyBuffer++ = r;
  954.                 --PixCount;
  955.                 }
  956.             }
  957.         Write(BMHandle,LineBuff,LBufLength);
  958.         DisLine(SavingWnd->RPort,"Line ",LineNum);
  959.         --LineNum;
  960.         }
  961.     Close(BMHandle);
  962.     if (SavingWnd) CloseWindow(SavingWnd);
  963.     if (LineBuff) FreeMem(LineBuff,LBufLength+4);
  964.     if (BMPHdrBuffer) FreeMem(BMPHdrBuffer,HdrSize);
  965. }
  966.  
  967. void SaveP(void)
  968. {
  969. DOUBLE *DblPtr;
  970. ULONG    *LngPtr;
  971.  
  972. UBYTE *DataBuf;
  973.     DataBuf = AllocMem(48,MEMF_CLEAR);
  974.     DblPtr = (DOUBLE *)DataBuf;
  975.     *DblPtr++ = XCenter;
  976.     *DblPtr++ = YCenter;
  977.     *DblPtr++ = HWidth;
  978.     *DblPtr++ = HHeight;
  979.     *DblPtr++ = Factor;
  980.     LngPtr = (LONG *)DblPtr;
  981.     *LngPtr++ = MaxCnt;
  982.     *LngPtr++ = Power;
  983.     OpenWrite((UBYTE *)"Mand.prm");
  984.     WriteFile(DataBuf,48);
  985.     CloseWrite();
  986.     if (DataBuf) FreeMem(DataBuf,48);
  987. }
  988.  
  989. void LoadP(void)
  990. {
  991. DOUBLE *DblPtr;
  992. ULONG    *LngPtr;
  993.  
  994. UBYTE *DataBuf;
  995.     DataBuf = AllocMem(48,MEMF_CLEAR);
  996.     FileHandle = Open((UBYTE *)"Mand.prm",MODE_OLDFILE);
  997.     if (!FileHandle)    {
  998.         printf("The file Mand.prm can't be found!\n");
  999.         return;
  1000.         }
  1001.     Read(FileHandle,DataBuf,48);
  1002.     Close(FileHandle);
  1003.     LastX = XCenter;
  1004.     LastY = YCenter;
  1005.     LastFactor = Factor;
  1006.     DblPtr = (DOUBLE *)DataBuf;
  1007.     XCenter = *DblPtr++;
  1008.     YCenter =*DblPtr++;
  1009.     HWidth = *DblPtr++;
  1010.     HHeight = *DblPtr++;
  1011.     Factor = *DblPtr++;
  1012.     DX = 1./Factor;
  1013.     LngPtr = (LONG *)DblPtr;
  1014.     MaxCnt = *LngPtr++;
  1015.     Power = *LngPtr++;
  1016.     if (DataBuf) FreeMem(DataBuf,48);
  1017.     WriteStuff();
  1018. }
  1019.  
  1020.  
  1021.  
  1022. UBYTE PaletteNumberFind( UBYTE Clr)
  1023. {
  1024. UBYTE NColor;
  1025.     NColor = Clr + 4;
  1026.     if (NColor > 16) NColor = NColor + 3;
  1027.     return(NColor);
  1028. }
  1029.  
  1030. void SmallPalette(void)
  1031. {
  1032. UWORD ColTab[] = {0,0x8,0xc,0xf,0x4c,0xc4,0xf0,0x4f0,0x880,0xc40,0xf00,0xf04,0xf08,0xf0c,0xf0f,0xa0a};
  1033.     LoadRGB4(&WBScreen->ViewPort,&ColTab[0],16);
  1034. }
  1035.  
  1036. void SetPalette(void)
  1037. {
  1038. UWORD *Src,*Dst;
  1039. DOUBLE    RShade;
  1040. int Mult1,Mult2,ColMax,BotCol;
  1041. ULONG CntCol;
  1042. ULONG NColor;
  1043. UBYTE    Shade,Shade2;
  1044.  
  1045.     if (WBScreen->RastPort.BitMap->Depth == 4)    NumColors = 16;
  1046.     if (WBScreen->RastPort.BitMap->Depth == 5)    NumColors = 32;
  1047.     if (WBScreen->RastPort.BitMap->Depth == 6)    NumColors = 64;
  1048.     if (WBScreen->RastPort.BitMap->Depth == 7)    NumColors = 128;
  1049.     if (WBScreen->RastPort.BitMap->Depth == 8)    NumColors = 256;
  1050.     TopCol = NumColors - 1;
  1051.     if (WBScreen->RastPort.BitMap->Depth < 5) {
  1052.         return;
  1053.         }
  1054.     if (SDepth >= 15) NumColors = 0x10000;
  1055.     if (NumColors <= 256) TableSize = 4000;
  1056.     else TableSize = 0x40000;
  1057.     OldColorTable = WBScreen->ViewPort.ColorMap->ColorTable;
  1058.     TopCol = NumColors - 1;
  1059.     NewColorTable = AllocMem(TableSize,MemMode);
  1060.     ColorTable32 = (UBYTE *)NewColorTable;
  1061.     if (!NewColorTable) {
  1062.         printf("Failed in allocation!\n");
  1063.         return;
  1064.         }
  1065.     CntCol = 0;
  1066.     Dst = (UWORD *)NewColorTable;
  1067.     Src = (UWORD *)OldColorTable;
  1068.     while (CntCol < NumColors)    {
  1069.         *Dst++ = *Src++;
  1070.         CntCol++;
  1071.         }
  1072.     ScreenToFront(WBScreen);
  1073.     if (NumColors > 256)    {
  1074.         Palette32();
  1075.         return;
  1076.         }
  1077.     WBScreen->ViewPort.ColorMap->ColorTable = NewColorTable;
  1078.     Mult1 = 4*256/NumColors;
  1079.     Mult2 = 3*Mult1/2;
  1080.     ColMax = NumColors/8;
  1081.     Mult2 = 6;
  1082.     Color = 0;
  1083.     BotCol = 4;
  1084.     SetRGB32(&(WBScreen->ViewPort),0,0xaa*BFactor,0xaa*BFactor,0xaa*BFactor);
  1085.     SetRGB32(&(WBScreen->ViewPort),1,0,0,0);
  1086.     SetRGB32(&(WBScreen->ViewPort),2,0xff*BFactor,0xff*BFactor,0xff*BFactor);
  1087.     SetRGB32(&(WBScreen->ViewPort),3,0x64*BFactor,0x88*BFactor,0xb8*BFactor);
  1088.     Color = 4;
  1089.     while (Color < ColMax)    {
  1090.         Shade = Mult1*Color + 128;
  1091.         Shade2 = Mult2*Color;
  1092.         NColor = PaletteNumberFind(Color);
  1093.         SetRGB32(&(WBScreen->ViewPort),NColor,0,BFactor*Shade2,BFactor*Shade);
  1094.         Color++;
  1095.         }
  1096.     while (Color < 2*ColMax)    {
  1097.         Shade = Color - ColMax;
  1098.         Shade2 = Mult2*Shade;
  1099.         Shade = Mult1*Shade + 128;
  1100.         NColor = PaletteNumberFind(Color);
  1101.         SetRGB32(&(WBScreen->ViewPort),NColor,BFactor*Shade,0,BFactor*Shade2);
  1102.         Color++;
  1103.         }
  1104.     while (Color < 3*ColMax)    {
  1105.         Shade = Color - 2*ColMax;
  1106.         Shade = Mult1*Shade + 128;
  1107.         RShade = 2.*Shade/3.;
  1108.         Shade2 = RShade;
  1109.         NColor = PaletteNumberFind(Color);
  1110.         SetRGB32(&(WBScreen->ViewPort),NColor,BFactor*Shade,BFactor*Shade2,0);
  1111.         Color++;
  1112.         }
  1113.     while (Color < 4*ColMax)    {
  1114.         Shade = Color - 3*ColMax;
  1115.         Shade2 = Mult2*Shade;
  1116.         Shade = Mult1*Shade + 128;
  1117.         NColor = PaletteNumberFind(Color);
  1118.         SetRGB32(&(WBScreen->ViewPort),NColor,BFactor*Shade,BFactor*Shade,BFactor*Shade2);
  1119.         Color++;
  1120.         }
  1121.     while (Color < 5*ColMax)    {
  1122.         Shade = Color - 4*ColMax;
  1123.         Shade = Mult1*Shade + 128;
  1124.         NColor = PaletteNumberFind(Color);
  1125.         if (NColor < TopCol)    SetRGB32(&(WBScreen->ViewPort),NColor,BFactor*Shade2,BFactor*Shade,0);
  1126.         Color++;
  1127.         }
  1128.     while (Color < 6*ColMax)    {
  1129.         Shade = Color - 5*ColMax;
  1130.         Shade2 = Mult2*Shade;
  1131.         Shade = Mult1*Shade + 128;
  1132.         NColor = PaletteNumberFind(Color);
  1133.         if (NColor < TopCol)    SetRGB32(&(WBScreen->ViewPort),NColor,0,BFactor*Shade,BFactor*Shade);
  1134.         Color++;
  1135.         }
  1136.     while (Color < 7*ColMax)    {
  1137.         Shade = Color - 6*ColMax;
  1138.         Shade = Mult1*Shade + 128;
  1139.         NColor = PaletteNumberFind(Color);
  1140.         if (NColor < TopCol)    SetRGB32(&(WBScreen->ViewPort),NColor,BFactor*Shade,0,BFactor*Shade);
  1141.         Color++;
  1142.         }
  1143.     while (Color < TopCol - 6)    {
  1144.         Shade = Color - 7*ColMax;
  1145.         Shade = Mult1*Shade + 96;
  1146.         Shade2 = Shade + 59;
  1147.         NColor = PaletteNumberFind(Color);
  1148.         if (NColor < TopCol)    SetRGB32(&(WBScreen->ViewPort),NColor,BFactor*Shade2,BFactor*Shade,BFactor*Shade2);
  1149.         Color++;
  1150.         }
  1151.     SetRGB32(&(WBScreen->ViewPort),TopCol,120*BFactor,0,120*BFactor);
  1152. }
  1153.  
  1154.  
  1155. void Palette32(void)
  1156. {
  1157. LONG C32Cnt;
  1158. UBYTE *Begin,*Dst;
  1159. UBYTE Red,Green,Blue;
  1160. BYTE dRed,dGreen,dBlue;
  1161.     Dst = (UBYTE *)NewColorTable;
  1162.     Begin = Dst;
  1163.     C32Cnt = 0;
  1164.     Red = 1;
  1165.     Green = 2;
  1166.     Blue = 128;
  1167.     dRed = 1;
  1168.     dGreen = 2;
  1169.     dBlue = 4;
  1170.     while (C32Cnt < 0xfffe)    {
  1171.         *Dst++ = 0;
  1172.         if (PalOpt == 0)    {
  1173.             *Dst++ = Red;
  1174.             *Dst++ = Green;
  1175.             *Dst++ = Blue;
  1176.             }
  1177.         if (PalOpt == 1)    {
  1178.             *Dst++ = Green;
  1179.             *Dst++ = Blue;
  1180.             *Dst++ = Red;
  1181.             }
  1182.         if (PalOpt == 2)    {
  1183.             *Dst++ = Blue;
  1184.             *Dst++ = Red;
  1185.             *Dst++ = Green;
  1186.             }
  1187.         if (PalOpt == 3)    {
  1188.             *Dst++ = Blue;
  1189.             *Dst++ = Green;
  1190.             *Dst++ = Red;
  1191.             }
  1192.         if (PalOpt == 4)    {
  1193.             *Dst++ = Green;
  1194.             *Dst++ = Red;
  1195.             *Dst++ = Blue;
  1196.             }
  1197.         if (PalOpt == 5)    {
  1198.             *Dst++ = Red;
  1199.             *Dst++ = Blue;
  1200.             *Dst++ = Green;
  1201.             }
  1202.         C32Cnt++;
  1203.         Blue = Blue + dBlue;
  1204.         Green = Green + dGreen;
  1205.         Red = Red + dRed;
  1206.         if ((Blue > 0xfb)||(Blue < 4))    dBlue = - dBlue;
  1207.         if ((Green >= 0xfd)||(Green < 2))    dGreen = - dGreen;
  1208.         if ((Red >= 0xfe)||(Red < 1))    dRed = - dRed;
  1209.         }
  1210.     *Dst++ = 0;
  1211.     *Dst++ = 0xff;
  1212.     *Dst++ = 0xff;
  1213.     *Dst++ = 0xff;
  1214.     *Dst++ = 0;
  1215.  
  1216.     if ((PalOpt == 0)||(PalOpt == 3))    {
  1217.         *Dst++ = 120;
  1218.         *Dst++ = 0;
  1219.         *Dst++ = 120;
  1220.         }
  1221.     if ((PalOpt == 1)||(PalOpt == 5))    {
  1222.         *Dst++ = 120;
  1223.         *Dst++ = 120;
  1224.         *Dst++ = 0;
  1225.         }
  1226.     if ((PalOpt == 2)||(PalOpt == 4))    {
  1227.         *Dst++ = 0;
  1228.         *Dst++ = 120;
  1229.         *Dst++ = 120;
  1230.         }
  1231.  
  1232.     Dst = Begin;
  1233.     WBScreen->ViewPort.ColorMap->ColorTable = NewColorTable;
  1234. }
  1235.  
  1236. void WindowSet()
  1237. {
  1238.  
  1239. nw.LeftEdge        =    0;
  1240. nw.TopEdge        =    0;            /* Expose screen drag bar */
  1241. nw.Width        =    64;
  1242. nw.Height        =    30;
  1243. nw.DetailPen    =    5;
  1244. nw.BlockPen        =    2;
  1245. nw.IDCMPFlags    =    CLOSEWINDOW ;
  1246. nw.Type            =    WBENCHSCREEN;
  1247. nw.Type            =    PUBLICSCREEN;
  1248. nw.Flags        =    WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SMART_REFRESH|ACTIVATE|REPORTMOUSE;
  1249. /*nw.Flags        =    WINDOWDRAG|WINDOWDEPTH|SMART_REFRESH|ACTIVATE|REPORTMOUSE | WFLG_NEWLOOKMENUS | WFLG_SIZEGADGET;*/
  1250. nw.FirstGadget    =    NULL;
  1251. nw.CheckMark    =    NULL;
  1252. nw.Screen        =    0;
  1253. WindowName     = &Title[0];
  1254. nw.Title        =    (UBYTE *)WindowName;
  1255. nw.BitMap        =    NULL;
  1256. nw.MinWidth        =    100;
  1257. nw.MinHeight    =    75;
  1258. nw.MaxWidth        =    SWidth+20;
  1259. nw.MaxHeight    =    SHeight+20;
  1260.     Delay(10);
  1261.     InfoWindow = (struct Window *)OpenWindow( &nw );
  1262.     WBScreen = InfoWindow -> WScreen;
  1263.     DefFont = WBScreen->Font;
  1264.     WBRast = InfoWindow -> RPort;
  1265.     MyPort    = InfoWindow -> UserPort;
  1266.     WBScreen = InfoWindow->WScreen;
  1267.     WDepth = WBScreen->RastPort.BitMap->Depth;
  1268.     FontHeight = 1.2*(DefFont->ta_YSize);
  1269.     TFHeight = GfxBase->DefaultFont->tf_YSize;
  1270.     IWHeight = 21*TFHeight;
  1271.     InfBTop = InfoWindow->BorderTop;
  1272.     InfBLeft = InfoWindow->BorderLeft;
  1273.     IWWidth = TextLength(WBRast,&Mesag7[0],strlen(Mesag7));
  1274.     TwoSpace = TextLength(WBRast,(STRPTR)"  ",2);
  1275.     IWWidth = IWWidth + 2*TwoSpace;
  1276.     if (IWHeight + InfBTop < WBScreen->Height)    ChangeWindowBox(InfoWindow,0,0,IWWidth+InfBLeft+InfoWindow->BorderRight,IWHeight+InfBTop);
  1277.     else ChangeWindowBox(InfoWindow,0,0,IWWidth+InfBLeft+InfoWindow->BorderRight,WBScreen->Height);
  1278.     SetWindowTitles(InfoWindow,(UBYTE *)" Information about this Fractal",(UBYTE *)-1);
  1279.     DFont = GfxBase->DefaultFont;
  1280.     if (!CWFont) CWFont = OpenFont(&topaz8);
  1281.     DefBold.ta_Name = DFont->tf_Message.mn_Node.ln_Name;
  1282.     DefBold.ta_YSize = 14*DFont->tf_YSize/10;
  1283.     DefBold.ta_Style = 2;
  1284.     if (DiskfontBase) BFont = OpenDiskFont(&DefBold);
  1285.     nw.BlockPen = 3;
  1286.  
  1287.     nw.Screen = WBScreen;
  1288.     IsCyberScreen = FALSE;
  1289.     ThisMode = WBScreen->ViewPort.ColorMap->VPModeID;
  1290.     BPP = 1;
  1291.     if (CyberGfxBase)    {
  1292.         if (IsCyberModeID(ThisMode))    {
  1293.             IsCyberScreen = TRUE;
  1294.             InitVS();
  1295.             }
  1296.         }
  1297.     SetPalette();
  1298. }
  1299.  
  1300.  
  1301. WORD LengthDescript()
  1302. {
  1303. WORD chPos;
  1304.     if (SysFlag == 0)    chPos = GetLength((STRPTR)" 68000");
  1305.     else    {
  1306.         if (SysFlag & 0x10) chPos = GetLength((STRPTR)" 68060");
  1307.         else if (SysFlag & 0x8) chPos = GetLength((STRPTR)" 68040");
  1308.         else if (SysFlag & 0x4) chPos = GetLength((STRPTR)" 68030");
  1309.         else if (SysFlag & 0x2) chPos = GetLength((STRPTR)" 68020");
  1310.         chPos = chPos + GetLength((STRPTR)"'");
  1311.         if (SysFlag & AFF_68882) chPos = chPos + GetLength((STRPTR)St882);
  1312.         else if (SysFlag & AFF_68881) chPos = chPos + GetLength((STRPTR)" 68881");
  1313.         }
  1314.     return(chPos);
  1315. }
  1316.  
  1317. void CheckCOPP()
  1318. {
  1319.     if (SysFlag & AFF_68882)    {
  1320.         Text(WBRast,(STRPTR)Comma,1);
  1321.         Text(WBRast,(STRPTR)&St882[0],strlen(St882));
  1322.         }
  1323.     else if (SysFlag & AFF_68881)    {
  1324.         Text(WBRast,(STRPTR)Comma,1);
  1325.         Text(WBRast,(STRPTR)" 68881",6);
  1326.         }
  1327. }
  1328.  
  1329. void DescribeSystem()
  1330. {
  1331.     Text(WBRast,&CPUStrBuf[0],strlen(CPUStrBuf));
  1332. }
  1333.  
  1334. WORD GetLength(TempMsg)
  1335. UBYTE *TempMsg;
  1336. {
  1337. WORD chPos;
  1338.     chPos = TextLength(WBRast,TempMsg,strlen(TempMsg));
  1339.     return(chPos);
  1340. }
  1341. WORD GethPos(TempMsg)
  1342. UBYTE *TempMsg;
  1343. {
  1344. WORD    chPos;
  1345.     chPos = TextLength(WBRast,TempMsg,strlen(TempMsg));
  1346.     chPos = IWWidth - chPos;
  1347.     chPos >>= 1;
  1348.     chPos = chPos + InfBLeft;
  1349.     return(chPos);
  1350. }
  1351.  
  1352.  
  1353. void DisCnt(void)
  1354. {
  1355. static char    SrtBuf[30];
  1356.     Move(WBRast,160,19*TFHeight);
  1357.     SetAPen(WBRast,2);
  1358.     sprintf(&SrtBuf[0],(STRPTR)"Working on line %d.        ",ytemp);
  1359.     Text(WBRast,(STRPTR)SrtBuf,strlen(SrtBuf));
  1360. }
  1361.  
  1362. void WriteStuff()
  1363. {
  1364. static    char    Mesage[]     = "SManMOS Beta 2.0 (3/28/2001)";
  1365. static    char    Mesag1[]     = "by David M. McKinstry";
  1366. static    char    Mesag2[]    = "Copyright ";
  1367. static    char    Mesag2c[]    = " 1998-2001";
  1368. char    StrngBuffer[200];
  1369. UBYTE    Mesag2b[]    = {0xa9};
  1370. ULONG    MemSize;
  1371. char *TmpPtr;
  1372. WORD vPos,hPos,chPos,SpcPlus;
  1373.     SpcPlus = 3*TFHeight/2;
  1374.     --SpcPlus;
  1375.     vPos = InfBTop + TFHeight;
  1376.     SetAPen(WBRast,1);
  1377.     chPos = GethPos(&Mesage[0]);
  1378.     Move(WBRast,chPos,vPos);
  1379.     Text(WBRast,(STRPTR)Mesage,strlen(Mesage));
  1380.     vPos = vPos + TFHeight;
  1381.     Mesag1[5] = 0x76;
  1382.     chPos = GethPos(&Mesag1[0]);
  1383.     Move(WBRast,chPos,vPos);
  1384.     Text(WBRast,(STRPTR)Mesag1,strlen(Mesag1));
  1385.     hPos = IWWidth/8;
  1386.     vPos = vPos + TFHeight;
  1387.     SetAPen(WBRast,3);
  1388.     chPos = TextLength(WBRast,&Mesag2[0],strlen(Mesag2));
  1389.     chPos = chPos + TextLength(WBRast,&Mesag2b[0],1);
  1390.     chPos = chPos + TextLength(WBRast,&Mesag2c[0],strlen(Mesag2c));
  1391.     chPos = IWWidth - chPos;
  1392.     chPos >>= 1;
  1393.     Move(WBRast,chPos,vPos);
  1394.     Text(WBRast,(STRPTR)Mesag2,strlen(Mesag2));
  1395.     Text(WBRast,(STRPTR)Mesag2b,1);
  1396.     Text(WBRast,(STRPTR)Mesag2c,strlen(Mesag2c));
  1397.     vPos = vPos + SpcPlus;
  1398.     SetAPen(WBRast,1);
  1399.     chPos = LengthDescript();
  1400.     chPos = chPos + GetLength(&Mesag3[0]);
  1401.     chPos = IWWidth - chPos;
  1402.     chPos >>= 1;
  1403.     Move(WBRast,40,vPos);
  1404.  
  1405.     Text(WBRast,(STRPTR)Mesag3,strlen(Mesag3));
  1406.     DescribeSystem();
  1407.  
  1408.     vPos = vPos + TFHeight;
  1409.     Move(WBRast,hPos,vPos);
  1410.     MemSize = AvailMem(MEMF_CHIP);
  1411.     TmpPtr = &ChpEnd[0];
  1412.     --TmpPtr;
  1413.     sprintf(TmpPtr,"%d",(int)MemSize);
  1414.     Text(WBRast,(STRPTR)ChpMsg,strlen(ChpMsg));
  1415.     Move(WBRast,61*IWWidth/100,vPos);
  1416.     MemSize = AvailMem(MEMF_FAST);
  1417.     TmpPtr = &FstEnd[0];
  1418.     --TmpPtr;
  1419.     sprintf(TmpPtr,"%d",(int)MemSize);
  1420.     Text(WBRast,(STRPTR)FstMsg,strlen(FstMsg));
  1421.  
  1422.     SetAPen(WBRast,2);
  1423.     vPos = vPos + SpcPlus;
  1424.     chPos = GethPos(Mesag4);
  1425.     Move(WBRast,chPos,vPos);
  1426.     Text(WBRast,(STRPTR)Mesag4,strlen(Mesag4));
  1427.  
  1428.     SetAPen(WBRast,1);
  1429.     vPos = vPos + SpcPlus;
  1430.  
  1431.     Move(WBRast,hPos,vPos);
  1432.     TmpPtr = &WdtEnd[0];
  1433.     sprintf(TmpPtr,"%d",WWidth);
  1434.     Text(WBRast,(STRPTR)WdtMsg,strlen(WdtMsg));
  1435.     Text(WBRast,(STRPTR)"        ",8);
  1436.     Move(WBRast,hPos + TextLength(WBRast,&WdtMsg[0],strlen(WdtMsg)),vPos);
  1437.     Text(WBRast,(STRPTR)TmpPtr,strlen(TmpPtr));
  1438.     Move(WBRast,61*IWWidth/100,vPos);
  1439.     TmpPtr = &HgtEnd[0];
  1440.     sprintf(TmpPtr,"%d",WHeight);
  1441.     Text(WBRast,(STRPTR)HgtMsg,strlen(HgtMsg));
  1442.     Text(WBRast,(STRPTR)"        ",8);
  1443.     Move(WBRast,61*IWWidth/100 + TextLength(WBRast,&HgtMsg[0],strlen(HgtMsg)),vPos);
  1444.     Text(WBRast,(STRPTR)TmpPtr,strlen(TmpPtr));
  1445.     vPos = vPos + SpcPlus;
  1446.     SetAPen(WBRast,1);
  1447.     TmpPtr = &MagMsg[16];
  1448.     sprintf(TmpPtr,"%e",Factor);
  1449.     Move(WBRast,hPos,vPos);
  1450.     Text(WBRast,(STRPTR)MagMsg,strlen(MagMsg));
  1451.  
  1452.     SetAPen(WBRast,1);
  1453.     TmpPtr = &CntEnd[0];
  1454.     sprintf(TmpPtr,(STRPTR)"%d",MaxCnt);
  1455.     Move(WBRast,61*IWWidth/100,vPos);
  1456.     Text(WBRast,(STRPTR)CntMsg,strlen(CntMsg));
  1457.     Text(WBRast,(STRPTR)"        ",8);
  1458.     Move(WBRast,61*IWWidth/100 + TextLength(WBRast,&CntMsg[0],strlen(CntMsg)),vPos);
  1459.     Text(WBRast,(STRPTR)TmpPtr,strlen(TmpPtr));
  1460.  
  1461.     vPos = vPos + SpcPlus;
  1462.     SetAPen(WBRast,3);
  1463.     chPos = GethPos(&ScrMsg[0]);
  1464.     Move(WBRast,chPos,vPos);
  1465.     Text(WBRast,(STRPTR)ScrMsg,strlen(ScrMsg));
  1466.  
  1467.     SetAPen(WBRast,1);
  1468.     vPos = vPos + TFHeight;
  1469.     Move(WBRast,hPos,vPos);
  1470.     TmpPtr = &XPsEnd[0];
  1471.     sprintf(TmpPtr,"%#.14e",(HWidth-XCenter)/Factor);
  1472.     Text(WBRast,(STRPTR)XPos,strlen(XPos));
  1473.     Text(WBRast,(STRPTR)"                          ",24);
  1474.     Move(WBRast,hPos+TextLength(WBRast,&XPos[0],strlen(XPos)),vPos);
  1475.     Text(WBRast,(STRPTR)TmpPtr,strlen(TmpPtr));
  1476.  
  1477.     Move(WBRast,61*IWWidth/100,vPos);
  1478.     TmpPtr = &YPsEnd[0];
  1479.     sprintf(TmpPtr,"%#.14e",(HHeight-YCenter)/Factor);
  1480.     Text(WBRast,(STRPTR)YPos,strlen(YPos));
  1481.     Text(WBRast,(STRPTR)"                          ",24);
  1482.     Move(WBRast,61*IWWidth/100+TextLength(WBRast,&YPos[0],strlen(YPos)),vPos);
  1483.     Text(WBRast,(STRPTR)TmpPtr,strlen(TmpPtr));
  1484.  
  1485.     SetAPen(WBRast,3);
  1486.     vPos = vPos + SpcPlus;
  1487.     if (PowerF == 0.) {
  1488.         if (Power < 10) chPos = GethPos(&MandMsg[0]);
  1489.         else    chPos = GethPos(&MandMsgG[0]);
  1490.         }
  1491.     else chPos = GethPos(&MandMsgP[0]);
  1492.     Move(WBRast,chPos,vPos);
  1493.     if (PowerF == 0.)    {
  1494.         if (Power < 10) Text(WBRast,(STRPTR)MandMsg,strlen(MandMsg));
  1495.         else    Text(WBRast,(STRPTR)MandMsgG,strlen(MandMsgG));
  1496.         }
  1497.     else {
  1498.         Text(WBRast,(STRPTR)MandMsgP,strlen(MandMsgP));
  1499.         MandMsgP[strlen(MandMsgP)-3] = 0x2d;
  1500.         SetDrMd(WBRast,JAM1);
  1501.         Move(WBRast,chPos,vPos);
  1502.         Text(WBRast,(STRPTR)MandMsgP,strlen(MandMsgP)-2);
  1503.         SetDrMd(WBRast,JAM2);
  1504.         MandMsgP[strlen(MandMsgP)-3] = 0x30;
  1505.         }
  1506.     vPos = vPos - TFHeight/3;
  1507.     if (PowerF == 0.) chPos = chPos + TextLength(WBRast,&MandMsg[0],18);
  1508.     else chPos = chPos + TextLength(WBRast,&MandMsgP[0],18);
  1509.     Move(WBRast,chPos,vPos);
  1510.     vPos = vPos + TFHeight/3;
  1511.  
  1512.     TmpPtr = &StrngBuffer[0];
  1513.     if (PowerF == 0.) {
  1514.         sprintf(TmpPtr,"%d",Power);
  1515.         if (Power < 10) Text(WBRast,(STRPTR)TmpPtr,1);
  1516.         else Text(WBRast,(STRPTR)TmpPtr,2);
  1517.         }
  1518.     else {
  1519.  
  1520.         sprintf(TmpPtr,"%#2.16f",PowerN);
  1521.         Text(WBRast,(STRPTR)TmpPtr,16);
  1522.         }
  1523.     if (((SysFlag & AFF_68881)||(SysFlag & AFF_68882))&&((SysFlag & AFF_68020)||(SysFlag & AFF_68030)))    CPU = 1;
  1524.  
  1525.     SetAPen(WBRast,2);
  1526.  
  1527.     vPos = vPos + SpcPlus;
  1528.     chPos = GethPos(&Mesag5[0]);
  1529.  
  1530.     vPos = vPos + 3*TFHeight/2;
  1531.  
  1532.     sprintf(&Mesag8[0],(STRPTR)"'Exploring the Julia Sets' is on the %d bit screen with palette option %d!",SDepth,PalOpt);
  1533.     chPos = GethPos(&Mesag8[0]);
  1534.     SetAPen(WBRast,1);
  1535.     Move(WBRast,chPos,vPos);
  1536.     Text(WBRast,(STRPTR)Mesag8,strlen(Mesag8));
  1537.  
  1538.     vPos = vPos + TFHeight;
  1539.     TmpPtr = &StrngBuffer[0];
  1540. /*    sprintf(TmpPtr,(STRPTR)"This task is located at %x!",MyTask);
  1541.     Move(WBRast,20,vPos);
  1542.     Text(WBRast,&StrngBuffer[0],strlen(&StrngBuffer[0]));*/
  1543.  
  1544. }
  1545.  
  1546. void LibsOpen()
  1547. {
  1548.     if (!DOSBase)    {
  1549.         DOSBase = (struct DosLibrary *)OpenLibrary((UBYTE *)"dos.library",0L);
  1550.         }
  1551.     DiskfontBase = (struct Library *)OpenLibrary((UBYTE *)"diskfont.library",0);
  1552.     GfxBase = (struct GfxBase *)OpenLibrary((UBYTE *)"graphics.library",0L);
  1553.  
  1554.     WarpBase = (struct Library *)OpenLibrary((UBYTE *)"powerpc.library",14L);
  1555.     IntuitionBase = (struct IntuitionBase *)OpenLibrary((UBYTE *)"intuition.library",0L);
  1556.     CyberGfxBase = (struct CyberGfxBase *)OpenLibrary((UBYTE *)"cybergraphics.library",40);
  1557. }
  1558.  
  1559. void LibsClose()
  1560. {
  1561.     if (WarpBase) CloseLibrary(WarpBase);
  1562.     if (DiskfontBase)    CloseLibrary(DiskfontBase);
  1563.  
  1564.     if (CyberGfxBase)    CloseLibrary((struct Library *)CyberGfxBase);
  1565.  
  1566.     if(GfxBase)            CloseLibrary((struct Library *)GfxBase);
  1567.  
  1568.     if(IntuitionBase)    CloseLibrary((struct Library *)IntuitionBase);
  1569.  
  1570.     }
  1571.  
  1572. void CheckMsg()
  1573. {
  1574. struct IntuiMessage *MyMsg;
  1575.     IMClass = 0;
  1576.     MyMsg = (struct IntuiMessage*) GetMsg(MyPort);
  1577.     if (MyMsg != NULL) {
  1578.           IMClass = MyMsg -> Class;
  1579.         ReplyMsg((struct Message *)MyMsg);
  1580.     }
  1581. }
  1582.  
  1583. void CheckIntMsg()
  1584. {
  1585. struct IntuiMessage *MyMsg;
  1586.     MenVal = 0;
  1587.     MyMsg = (struct IntuiMessage*) GetMsg(IntPort);
  1588.     if (MyMsg != NULL) {
  1589.         MenVal = MyMsg -> Code;
  1590.         IMClass = MyMsg -> Class;
  1591.         ReplyMsg((struct Message *)MyMsg);
  1592.     }
  1593. }
  1594.  
  1595. void ErrorDisplay()
  1596. {
  1597. static    char    Err020[]    = "You are running SMan on an Amiga without a math coprocessor!";
  1598. static    char    Err021[]    = "Although this is probably working, it must be incredibly slow!";
  1599. static    char    Err022[]    = "Please run SMan on an adequate machine!";
  1600. static    char    Err023[]    = "Use the Close Gadget to Terminate.";
  1601.     SetRast(WBRast,0);
  1602.     SetAPen(WBRast,1);
  1603.     Move(WBRast,40,80);
  1604.     Text(WBRast,(STRPTR)Err020,strlen(Err020));
  1605.     Move(WBRast,40,95);
  1606.     Text(WBRast,(STRPTR)Err021,strlen(Err021));
  1607.     Move(WBRast,40,125);
  1608.     Text(WBRast,(STRPTR)Err022,strlen(Err022));
  1609.     SetAPen(WBRast,3);
  1610.     Move(WBRast,40,155);
  1611.     Text(WBRast,(STRPTR)Err023,strlen(Err023));
  1612.     WindowToFront(InfoWindow);
  1613.     IMClass = 0;
  1614.     while (IMClass != CLOSEWINDOW)    {
  1615.         CheckMsg();
  1616.         Delay(1);
  1617.         }
  1618. }
  1619.  
  1620.  
  1621. void CountChange()
  1622. {
  1623.     if((MenVal & 0xff) == 1)    MaxCnt = MaxCnt + 8;
  1624.     if((MenVal & 0xff) == 0x21)    MaxCnt = MaxCnt - 8;
  1625.     if((MenVal & 0xff) == 0x41)    MaxCnt = 2*MaxCnt;
  1626.     if((MenVal & 0xff) == 0x61) MaxCnt = MaxCnt/2;
  1627.     if (MaxCnt < 8)    MaxCnt = 8;
  1628.     WriteStuff();
  1629.     ActivateWindow(IntWindow);
  1630. }
  1631.  
  1632. void Restore(void)
  1633. {
  1634.     Factor = LastFactor;
  1635.     DX = 1./Factor;
  1636.     XCenter = LastX;
  1637.     YCenter = LastY;
  1638.     MenVal = 0xf820;    /* Force Redraw! */
  1639. }
  1640.  
  1641. void DrawPoly(void)
  1642. {
  1643. UWORD    xS,yS,xE,yE;
  1644.     PolyPnt = &PolyTab[0];
  1645.     xS = *PolyPnt++;
  1646.     yS = *PolyPnt++;
  1647.     xE = *PolyPnt++;
  1648.     yE = *PolyPnt++;
  1649.     LineToggle(xS,yS,xE,yE);
  1650.     xS = xE;
  1651.     yS = yE;
  1652.     xE = *PolyPnt++;
  1653.     yE = *PolyPnt++;
  1654.     LineToggle(xS,yS,xE,yE);
  1655.     xS = xE;
  1656.     yS = yE;
  1657.     xE = *PolyPnt++;
  1658.     yE = *PolyPnt++;
  1659.     LineToggle(xS,yS,xE,yE);
  1660.     xS = xE;
  1661.     yS = yE;
  1662.     xE = *PolyPnt++;
  1663.     yE = *PolyPnt++;
  1664.     LineToggle(xS,yS,xE,yE);
  1665. }
  1666.  
  1667. void PolyUpDate(void)
  1668. {
  1669.     PolyPnt = &PolyTab[0];
  1670.     x2 = IntWindow -> MouseX;
  1671.     *PolyPnt++ = x1;        /* Upper-Left Corner */
  1672.     *PolyPnt++ = y1;
  1673.     *PolyPnt++ = x2;        /* Upper-Right Corner */
  1674.     *PolyPnt++ = y1;
  1675.     DeltaX = x2 - x1;
  1676.     DeltaY = WHeight*DeltaX/WWidth;
  1677.     y2 = y1 + DeltaY;
  1678.     *PolyPnt++ = x2;        /* Lower-Right Corner */
  1679.     *PolyPnt++ = y2;
  1680.     *PolyPnt++ = x1;        /* Lower-Left Corner */
  1681.     *PolyPnt++ = y2;
  1682.     *PolyPnt++ = x1;        /* Upper-Left Corner */
  1683.     *PolyPnt++ = y1;
  1684.     Move(CWRast,x1,y1);
  1685.     PolyPnt = &PolyTab[0];
  1686.     DrawPoly();
  1687. }
  1688.  
  1689. /* Clear by reversing again */
  1690. void PolyClear(void)
  1691. {
  1692.     PolyPnt = &PolyTab[0];
  1693.     DrawPoly();
  1694. }
  1695. /*WaitChg will wait until there is at least a difference of 10 between
  1696.  the original MouseX value and the new. */
  1697.  
  1698. void WaitChg(void)
  1699. {
  1700.     while ((x2 - x1) < 5)    {
  1701.         x2 = IntWindow -> MouseX;
  1702.         Delay(1);
  1703.         }
  1704. }
  1705. void DoZoom(void)
  1706. {
  1707. double Ratio;
  1708.     x1 = 0;
  1709.     y1 = 0;
  1710.     x2 = 0;
  1711.     y2 = 0;
  1712.     while (MenVal != SELECTDOWN)    {
  1713.         x1 = IntWindow -> MouseX;
  1714.         y1 = IntWindow -> MouseY;
  1715.         CheckIntMsg();
  1716.         }
  1717.     x1 = IntWindow -> MouseX;
  1718.     y1 = IntWindow -> MouseY;
  1719.  
  1720. /* Now prep for complementary polygon (i.e. rectangle) */
  1721.     SetDrMd(CWRast,2);
  1722.     WaitChg();
  1723.     PolyUpDate();
  1724.     while (MenVal != SELECTUP)    {
  1725.         CheckIntMsg();
  1726.         PolyClear();
  1727.         PolyUpDate();
  1728.         Delay(1);
  1729.         }
  1730. /* Clear Polygon and restore drawing mode */
  1731.     PolyClear();
  1732.     SetDrMd(CWRast,0);
  1733.     LastFactor = Factor;
  1734.     LastX = XCenter;
  1735.     LastY = YCenter;
  1736.  
  1737.     Ratio = XWidth/DeltaX;
  1738.     Factor = Ratio*Factor;
  1739.     DX = 1./Factor;
  1740.     XCenter = XCenter - (double)(x1 - BLeft);
  1741.     XCenter = Ratio*XCenter;
  1742.     YCenter = YCenter - (double)(y1 - BTop);
  1743.     YCenter = Ratio*YCenter;
  1744.     MenVal = 0xf820;
  1745. }
  1746.  
  1747.  
  1748.  
  1749. void Zoom(void)
  1750. {
  1751.     xtemp = RightEdge;
  1752.     if ((MenVal & 0xf0) == 0xc0)    {
  1753.         PalOpt++;
  1754.         if (PalOpt > 5) PalOpt = 0;
  1755.         Palette32();
  1756.         }
  1757.  
  1758.     if((MenVal & 0xf0) == 0x00)    DoZoom();
  1759.     if(MenVal == 0xf822)    Restore();
  1760.     if((MenVal & 0xf0) == 0x40)    {
  1761.         --Power;
  1762.         if (PowerF == 0.)    {
  1763.             if (Power < 2) Power = 2;
  1764.             }
  1765.         else if (Power < 1) Power = 1;
  1766.         SetRast(WBRast,0);
  1767.         ActivateWindow(InfoWindow);
  1768.         }
  1769.     if((MenVal & 0xf0) == 0x60)    {
  1770.         Power++;
  1771.         if (Power > 99) {
  1772.             Power = 9;
  1773.             }
  1774.         SetRast(WBRast,0);
  1775.         ActivateWindow(InfoWindow);
  1776.         }
  1777.     if((MenVal & 0xf0) == 0x80)    {
  1778.         LastFactor = Factor;
  1779.         LastX = XCenter;
  1780.         LastY = YCenter;
  1781.         XCenter = 2.*(XCenter - HWidth);
  1782.         YCenter = 2.*(YCenter - HHeight);
  1783.         XCenter = XCenter + HWidth;
  1784.         YCenter = YCenter + HHeight;
  1785.  
  1786.         Factor = 2.*Factor;
  1787.         DX = 1./Factor;
  1788.         MenVal = 0xf820;
  1789.         }
  1790.     if((MenVal & 0xf0) == 0xa0)    {
  1791.         LastFactor = Factor;
  1792.         LastX = XCenter;
  1793.         LastY = YCenter;
  1794.         XCenter  = 0.5*(XCenter - HWidth);
  1795.         YCenter = 0.5*(YCenter - HHeight);
  1796.         XCenter = XCenter + HWidth;
  1797.         YCenter = YCenter + HHeight;
  1798.         Factor = Factor/2.;
  1799.         DX = 1./Factor;
  1800.         MenVal = 0xf820;
  1801.     }
  1802.     WriteStuff();
  1803. }
  1804.  
  1805.  
  1806. void SManMen(void)
  1807. {
  1808.         if (MenVal == 0xf800)    {
  1809.             WriteStuff();
  1810.             WBenchToFront();
  1811.             WindowToFront(InfoWindow);
  1812.             ActivateWindow(InfoWindow);
  1813.             }
  1814.         if (MenVal == 0xf840)    {
  1815.             SaveBMP();
  1816.             MenVal = 0;
  1817.             }
  1818.         if (MenVal == 0xf860)    {
  1819.             Save();
  1820.             MenVal = 0;
  1821.             }
  1822.         if (MenVal == 0xf880)    {
  1823.             SaveP();
  1824.             MenVal = 0;
  1825.             }
  1826.         if (MenVal == 0xf8a0)    {
  1827.             LoadP();
  1828.             MenVal = 0xf820;
  1829.             }
  1830. }
  1831.  
  1832.  
  1833.  
  1834. void FullCheck(void)
  1835. {
  1836. USHORT    SavVal;
  1837. ULONG    SavCls;
  1838.  
  1839. struct IntuiMessage *MyMsg;
  1840.         IMClass = 0;
  1841.         MenVal = 0;
  1842.         CheckMsg();
  1843.         if (IMClass == CLOSEWINDOW) {
  1844.             ScreenToFront(IntWindow->WScreen);
  1845.             WindowToFront(IntWindow);
  1846.             }
  1847.         CheckIntMsg();
  1848.         if (IMClass == CLOSEWINDOW) {
  1849.             ScreenToFront(IntWindow->WScreen);
  1850.             WindowToFront(IntWindow);
  1851.             MenVal = 0xf8c0;
  1852.             return;
  1853.             }
  1854.         if (MenVal)     {
  1855.             SavVal = MenVal;
  1856.             SavCls = IMClass;
  1857.             while (MenVal == MENUDOWN)    {    /*Was MENUPICK */
  1858.                 CheckIntMsg();
  1859.                 }
  1860.             MenVal = SavVal;
  1861.             IMClass = SavCls;
  1862.             if (SavVal == 0xffff)    {
  1863.                 MenVal = 0;
  1864.                 }
  1865.             }
  1866.         if (IMClass == IDCMP_NEWSIZE) {
  1867.             while (IMClass == IDCMP_NEWSIZE)    {
  1868.                 IMClass = 0;
  1869.                 MyMsg = (struct IntuiMessage*) GetMsg(IntWindow -> UserPort);
  1870.                 if (MyMsg)    {
  1871.                     IMClass = MyMsg -> Class;
  1872.                     ReplyMsg((struct Message *)MyMsg);
  1873.                     }
  1874.                 }
  1875.             GetWindowSize();
  1876.             MenVal = 0xf820;    /* Force a redraw */
  1877.             }
  1878.  
  1879.         if (MenVal & 0xf800) {
  1880.             if ((MenVal & 0xf) == 1) {
  1881.                 CountChange();
  1882.                 MenVal = 0;
  1883.                 }
  1884.             if ((MenVal & 0xf) == 3) PowerChange();
  1885.             if (MenVal == 0xf800)    {
  1886.                 WriteStuff();
  1887.                 WBenchToFront();
  1888.                 WindowToFront(InfoWindow);
  1889.                 ActivateWindow(InfoWindow);
  1890.                 MenVal = 0;
  1891.                 }
  1892.             if (MenVal == 0xf8c0) xtemp = RightEdge;    /* Quit */
  1893.             if (MenVal == 0xf840) xtemp = RightEdge;    /* Save BMP */
  1894.             if (MenVal == 0xf860) SaveIFF = TRUE;        /* Save iff */
  1895.             if (MenVal == 0xf880) xtemp = RightEdge;    /* SaveP */
  1896.             if (MenVal == 0xf8a0) xtemp = RightEdge;    /* LoadP */
  1897.             if ((MenVal & 0xf80f) == 0xf802) xtemp = RightEdge;    /* Zoom */
  1898.             if ((MenVal & 0xf820) == 0xf820) xtemp = RightEdge; /* Redraw */
  1899.             }
  1900. }
  1901.  
  1902.  
  1903.  
  1904. void PlotIt(UWORD Clr)
  1905. {
  1906. ULONG *ColSrc;
  1907. int BotCol,TopCol;
  1908.     if (Clr != 0xffff)    {
  1909.         if (Clr > LastMax) {
  1910.             LastMax = Clr;
  1911.             }
  1912.         }
  1913.         if (NumColors == 16)    {
  1914.             BotCol = 0;
  1915.             TopCol = 15;
  1916.             }
  1917.         else {
  1918.             BotCol = 4;
  1919.             TopCol = NumColors - 1;
  1920.             }
  1921.         if (Clr == 0xffff) {
  1922.                    Clr = TopCol;
  1923.             }
  1924.         else if (Clr > (TopCol - BotCol)) {
  1925.                 while (Clr > (TopCol - BotCol)) Clr = Clr - (TopCol - BotCol);
  1926.                 }
  1927.         if (Clr != TopCol) Clr  = Clr + BotCol;
  1928.         if (Clr == 17) Clr = 20;
  1929.         if (Clr == 18) Clr = 21;
  1930.         if (Clr == 19) Clr = 22;
  1931.  
  1932.         *PixelBuf++ = (UBYTE)(Clr & 0xff);
  1933. }
  1934.  
  1935.  
  1936. void GetWindowSize(void)
  1937. {
  1938. WORD OldWidth,OldHeight;
  1939.     OldWidth = WWidth;
  1940.     OldHeight = WHeight;
  1941.     BLeft = (LONG)IntWindow->BorderLeft;
  1942.     BTop = (LONG)IntWindow->BorderTop;
  1943.     RightEdge = IntWindow->GZZWidth;
  1944.     FarEdge = IntWindow->GZZHeight;
  1945.     WWidth = RightEdge;
  1946.     WHeight = FarEdge;
  1947.     XWidth = WWidth;
  1948.     XHeight = WHeight;
  1949.     XC = RightEdge/2;
  1950.     YC = FarEdge/2;
  1951.     HWidth = XC;
  1952.     HHeight = YC;
  1953.     XCenter = XCenter + 0.5*(double)(WWidth - OldWidth);
  1954.     YCenter = YCenter + 0.5*(double)(WHeight - OldHeight);
  1955.     WriteStuff();
  1956. }
  1957.  
  1958. void PowerChange()
  1959. {
  1960.     if ((MenVal & 0xf0) == 0) {
  1961.         DeltaP = 0.1;
  1962.         }
  1963.     if ((MenVal & 0xf0) == 0x20) {
  1964.         DeltaP = 0.0;
  1965.         PowerF = 0.;
  1966.         }
  1967.     if ((MenVal & 0xf0) == 0x40) {
  1968.         DeltaP = DeltaP/10.;
  1969.         if (DeltaP < 1.e-14) DeltaP = 1.e-14;
  1970.         }
  1971.     if ((MenVal & 0xf0) == 0x60) {
  1972.         DeltaP = 10.0*DeltaP;
  1973.         if (DeltaP > 0.1) DeltaP = 0.1;
  1974.         }
  1975.     if ((MenVal & 0xf0) == 0x80) {
  1976.         PowerF = PowerF + DeltaP;
  1977.         if (PowerF >= 1.0)    {
  1978.             PowerF = PowerF - 1.0;
  1979.             Power++;
  1980.             if (Power > 99) Power = 9;
  1981.             xtemp = RightEdge;
  1982.             }
  1983.         }
  1984.     if ((MenVal & 0xf0) == 0xa0) {
  1985.         PowerF = PowerF - DeltaP;
  1986.         if (PowerF < 0.)    {
  1987.             --Power;
  1988.             PowerF = PowerF + 1.0;
  1989.             if (Power < 1) {
  1990.                 Power = 1;
  1991.                 }
  1992.             }
  1993.         }
  1994.     SetRast(WBRast,0);
  1995.     ActivateWindow(InfoWindow);
  1996.     WriteStuff();
  1997.     ActivateWindow(IntWindow);
  1998.     MenVal = 0;
  1999. }
  2000.  
  2001. int LineCheck(void)
  2002. {
  2003.         CheckMsg();
  2004.         if (IMClass == CLOSEWINDOW)    {
  2005.             ScreenToFront(IntWindow->WScreen);
  2006.             WindowToFront(IntWindow);
  2007.             ActivateWindow(IntWindow);
  2008.             }
  2009.         if ((!MenVal) && (!IMClass)) CheckIntMsg();
  2010.         if (MenVal)    {
  2011.             if ((MenVal & 0xf) == 1)    CountChange();
  2012.             if (MenVal == 0xf8c0)    return(TRUE);
  2013.             if ((MenVal & 0xf) == 2) {
  2014.                 Zoom();
  2015.                 if (MenVal == 0xf820) return(TRUE);
  2016.                 }
  2017.             if ((MenVal & 0xf) == 0)    {
  2018.                 SManMen();
  2019.                 if((MenVal & 0xff) == 0x20)    return(TRUE);
  2020.                 }
  2021.             if ((MenVal & 0xf) == 3) PowerChange();
  2022.             }
  2023. }
  2024.  
  2025.  
  2026. void WritePixels(ULONG *MyPixelBuf,ULONG Width,ULONG Height)
  2027. {
  2028. APTR fpp;
  2029. ULONG NumPixels,BaseAdr,xOff,yOff,xyOff,xLoc,yLoc;
  2030. ULONG *DstBuf,*LastBase;
  2031.     NumPixels = Width*Height;
  2032. /*    fpp =
  2033. LockBitMapTags(&WBScreen->BitMap,LBMI_BASEADDRESS,&BaseAdr,TAG_DONE);*/
  2034.     BaseAdr = 0xe0000000;
  2035.     xOff = IntWindow->LeftEdge + IntWindow->BorderLeft;
  2036.     yOff = IntWindow->TopEdge + IntWindow->BorderTop;
  2037.     yOff = yOff*WBScreen->Width;
  2038.     xyOff = xOff + yOff;
  2039.     DstBuf = (ULONG *)BaseAdr + xyOff;
  2040.     LastBase = DstBuf;
  2041.     yLoc = 0;
  2042.     while (yLoc < Height)    {
  2043.         xLoc = 0;
  2044.         while (xLoc < Width)    {
  2045.             *DstBuf++ = *MyPixelBuf++;
  2046.             xLoc++;
  2047.             }
  2048.         yLoc++;
  2049.         DstBuf = LastBase + WBScreen->Width;
  2050.         LastBase = DstBuf;
  2051.         }
  2052. /*     if (fpp) UnLockBitMap(fpp);*/
  2053. }
  2054.  
  2055. void GreyPixels(ULONG *MyPixelBuf,ULONG Width,ULONG Height)
  2056. {
  2057. ULONG NumPixels,PixCnt;
  2058.     NumPixels = Width*Height;
  2059.     PixCnt = 0;
  2060.     while (PixCnt < NumPixels)    {
  2061.         *MyPixelBuf++ = 0xaaaaaa;
  2062.         PixCnt++;
  2063.         }
  2064. }
  2065.  
  2066.  
  2067. BOOL InputCheck(void)
  2068. {
  2069. UWORD RBVal;
  2070. UBYTE Val1,Val2;
  2071.     *DDRAV = 3;
  2072.     Val1 = *SDRV;
  2073.     if (Val1) *SDRV = 0;
  2074.     if (Val1 == 0x31) return(TRUE);
  2075.     Val2 = *PDRAAV;
  2076.     if (!(Val2 & 0x40)) return(TRUE);
  2077.     RBVal = ((*POTGOR)& 0x400);
  2078.     if (RBVal != 0x400) return(TRUE);
  2079.     return(FALSE);
  2080. }
  2081.  
  2082.  
  2083. void FullSurface()
  2084. {
  2085. double yRel;
  2086. UWORD BorLft,BorTop;
  2087. BOOL IPCheck;
  2088. int RepCntr;
  2089.  
  2090.        BorLft = IntWindow->BorderLeft;
  2091.     BorTop = IntWindow->BorderTop;
  2092.     ytemp = NearEdge;
  2093.     Limit = Two*Factor;
  2094.     Limit = Limit*Limit;
  2095.     PixelBuf = WindowBuf;
  2096.     LPixelBuf = (ULONG *)PixelBuf;
  2097.     PowerN = (double)Power + PowerF;
  2098.     GetSysTime(&CurTime);
  2099.     Secs = CurTime.tv_secs;
  2100.     Micros = CurTime.tv_micro;
  2101.     while (ytemp < FarEdge)    {
  2102.         yRel = (double)ytemp - YCenter;
  2103.         yRel = yRel*DX;
  2104.         if ((PowerF != 0.)||(Power > 7))    {
  2105.             FncFnd(yRel);
  2106.             }
  2107.  
  2108. /*        else    {
  2109.             switch(Power)    {*/
  2110.         else switch(Power)    {
  2111.  
  2112.             case 2:
  2113.                 UseLibP2(yRel);
  2114.                 break;
  2115.  
  2116.             case 3:
  2117.                 UseLibP3(yRel);
  2118.                 break;
  2119.  
  2120.             case 4:
  2121.                 UseLibP4(yRel);
  2122.                 break;
  2123.  
  2124.             case 5:
  2125.                 UseLibP5(yRel);
  2126.                 break;
  2127.  
  2128.             case 6:
  2129.                 UseLibP6(yRel);
  2130.                 break;
  2131.  
  2132.             case 7:
  2133.                 UseLibP7(yRel);
  2134.                 break;
  2135.                 }
  2136. /*            }*/
  2137.  
  2138.         IPCheck = FALSE;
  2139.         IPCheck = InputCheck();
  2140.         if (IPCheck)    {
  2141.             FullCheck();
  2142.             CheckMsg();
  2143.             if (IMClass == CLOSEWINDOW)    {
  2144.                 ScreenToFront(IntWindow->WScreen);
  2145.                 WindowToFront(IntWindow);
  2146.                 ActivateWindow(IntWindow);
  2147.                 }
  2148.             if ((!MenVal) && (!IMClass)) CheckIntMsg();
  2149.             if (MenVal)    {
  2150.                 if ((MenVal & 0xf) == 1)    CountChange();
  2151.                 if (MenVal == 0xf8c0)    return;
  2152.                 if ((MenVal & 0xf) == 2) {
  2153.                     Zoom();
  2154.                     if (MenVal == 0xf820) return;
  2155.                     }
  2156.                 if ((MenVal & 0xf) == 0)    {
  2157.                     SManMen();
  2158.                     if((MenVal & 0xff) == 0x20)    return;
  2159.                     }
  2160.                 if ((MenVal & 0xf) == 3) PowerChange();
  2161.             }
  2162.         }
  2163.     if (NumColors <= 256)    {
  2164.             WritePixelLine8(IntWindow->RPort,BorLft,BorTop+ytemp,WWidth,WindowBuf,&MainWRast);
  2165.             PixelBuf = WindowBuf;
  2166.             }
  2167.         ytemp++;
  2168.         if ((ytemp & 0x3f)== 0) {
  2169.              if (MaxCnt > 256) DisCnt();
  2170.             }
  2171.  
  2172.     }
  2173.  
  2174.     GetSysTime(&CurTime);
  2175.     if (CurTime.tv_micro < Micros)    {
  2176.         CurTime.tv_micro = CurTime.tv_micro + 1000000;
  2177.         CurTime.tv_secs = CurTime.tv_secs - 1;
  2178.         }
  2179.     ElTime = CurTime.tv_secs - Secs + (CurTime.tv_micro - Micros)/1000000.;
  2180.  
  2181.     if (NumColors > 256)    {
  2182.         WritePixelArray((APTR*)WindowBuf,0,0,4*WWidth,IntWindow->RPort,BorLft,BorTop,WWidth,WHeight,RECTFMT_ARGB);
  2183.         LPixelBuf = (ULONG *)WindowBuf;
  2184.     }
  2185.     SetAPen(WBRast,1);
  2186.     sprintf(&MyStringBuf[0],"Time to generate last complete image was %e seconds.",ElTime);
  2187.     Move(WBRast,20,InfoWindow->Height - 20);
  2188.     Text(WBRast,(STRPTR)&MyStringBuf[0],strlen(MyStringBuf));
  2189.     MenVal = 0;
  2190.     IMClass = 0;
  2191. }
  2192.  
  2193. void Status()
  2194. {
  2195. struct IntuiMessage *MyMsg;
  2196.     IMClass = 0;
  2197.     MenVal = 0;
  2198.     while (!MenVal)    {
  2199.         Delay(1);
  2200.         CheckMsg();
  2201.         if (IMClass == CLOSEWINDOW)    {
  2202.             ScreenToFront(IntWindow->WScreen);
  2203.             WindowToFront(IntWindow);
  2204.             ActivateWindow(IntWindow);
  2205.             }
  2206.         if (!MenVal) CheckIntMsg();
  2207.         if (IMClass == CLOSEWINDOW) MenVal = 0xf8c0;
  2208.         if ((MenVal & 0xff7f) == 0x68) MenVal = 0;
  2209.         if (MenVal & 0xf800)    {
  2210.             if (MenVal == 0xffff) MenVal = 0;
  2211.             if ((MenVal & 0xf) == 0)    {
  2212.                 SManMen();
  2213.                 if (MenVal == 0xf800) MenVal = 0;
  2214.                 }
  2215.             if ((MenVal & 0xf) == 1)    CountChange();
  2216.             if ((MenVal & 0xf) == 2)    Zoom();
  2217.             if ((MenVal & 0xf) == 3) PowerChange();
  2218.             if (MenVal == 0xf840)    {
  2219.                 SaveBMP();
  2220.                 MenVal = 0;
  2221.                 }
  2222.             if (MenVal == 0xf860)    {
  2223.                 Save();
  2224.                 MenVal = 0;
  2225.                 }
  2226.             if (MenVal == 0xf880)    {
  2227.                 SaveP();
  2228.                 MenVal = 0;
  2229.                 }
  2230.             if (MenVal == 0xf8A0)    {
  2231.                 LoadP();
  2232.                 MenVal = 0xf820;    /* Force a redraw */
  2233.                 }
  2234.             }
  2235.         if (IMClass == IDCMP_NEWSIZE) {
  2236.             while (IMClass == IDCMP_NEWSIZE)    {
  2237.                 IMClass = 0;
  2238.                 MyMsg = (struct IntuiMessage*) GetMsg(IntWindow -> UserPort);
  2239.                 if (MyMsg)    {
  2240.                     IMClass = MyMsg -> Class;
  2241.                     ReplyMsg((struct Message *)MyMsg);
  2242.                     }
  2243.                 }
  2244.             GetWindowSize();
  2245.             MenVal = 0xf820;    /* Force a redraw */
  2246.             }
  2247.     }
  2248. }
  2249.  
  2250. void RestoreOrigColors()
  2251. {
  2252. UWORD *MyTable;
  2253. SHORT CCount;
  2254.     MyTable = OldColorTable;
  2255.     CCount = 0;
  2256.     while (CCount < NumColors) {
  2257.         MySetRGB(CCount,*MyTable++);
  2258.         CCount++;
  2259.         }
  2260. }
  2261.  
  2262. void MySetRGB(Color,Value)
  2263. SHORT Color;
  2264. USHORT Value;
  2265. {
  2266. UBYTE Red,Green,Blue;
  2267. USHORT SRed,SGreen,SBlue;
  2268.     SRed = Value;
  2269.     SRed >>=8;
  2270.     Red = (UBYTE)SRed;
  2271.     SGreen = 0xf0 & Value;
  2272.     SGreen >>=4;
  2273.     Green = (UBYTE)SGreen;
  2274.     SBlue = 0xf & Value;
  2275.     Blue = (UBYTE)SBlue;
  2276.     SETRGB(WBScreen,Color,Red,Green,Blue);
  2277. }
  2278.  
  2279.  
  2280. void CPUStuff(void)
  2281. {
  2282.  
  2283. int StrLength;
  2284.     sprintf(&CPUStrBuf[0],"PowerPC ");    /* Well duh!! it's running on MorphOS isn't it.*/
  2285.     StrLength = strlen(CPUStrBuf);
  2286.     sprintf(&CPUStrBuf[StrLength],"CPU at %#.2f MHz ",ClkFrq/1.e6);
  2287.     StrLength = strlen(CPUStrBuf);
  2288.     sprintf(&CPUStrBuf[StrLength],"with bus clock of %#.2f MHz. ",BusFrq/1.e6);
  2289. }
  2290.  
  2291.  
  2292. void ClockGet(void)
  2293. {
  2294. LONG OldPri;
  2295. double TotTic,Freq,Multip;
  2296. int IMult;
  2297.  
  2298.     OldPri = SetTaskPri(MyTask,20);
  2299.     TimeGet();
  2300.     GetSysTime(&CurTime);
  2301.     Secs = CurTime.tv_secs;
  2302.     Micros = CurTime.tv_micro;
  2303.     Time1Hi = TimeHi;
  2304.     Time1Lo = TimeLo;
  2305.     Delay(20);
  2306.     TimeGet();
  2307.     GetSysTime(&CurTime);
  2308.     if (CurTime.tv_micro < Micros)    {
  2309.         CurTime.tv_micro = CurTime.tv_micro + 1000000;
  2310.         CurTime.tv_secs = CurTime.tv_secs - 1;
  2311.         }
  2312.     Time2Hi = TimeHi;
  2313.     Time2Lo = TimeLo;
  2314.     ElTime = CurTime.tv_secs - Secs + (CurTime.tv_micro - Micros)/1000000.;
  2315.     TotTic = (double)(Time2Lo - Time1Lo);
  2316.     if (TotTic < 0.)    {
  2317.         TotTic = TotTic + (65536.*65536.);
  2318.         Time2Hi--;
  2319.         TotTic = TotTic + 655536.*65536.*(double)(Time2Hi - Time1Hi);
  2320.         }
  2321.     else    {
  2322.         TotTic = TotTic + 655536.*65536.*(double)(Time2Hi - Time1Hi);
  2323.         }
  2324.  
  2325.     ClkFrq = TotTic/ElTime;
  2326.     BusFrq = 4*ClkFrq;
  2327.  
  2328.     GetSysTime(&CurTime);
  2329.     Secs = CurTime.tv_secs;
  2330.     Micros = CurTime.tv_micro;
  2331. /* Note that within TimeGet2, it's assumed that each floating point
  2332. multiplication is 3 clock cycles.  This is the basis for the kludged
  2333. determination of the CPU frequency. */
  2334.     TimeGet2();
  2335.     GetSysTime(&CurTime);
  2336.     if (CurTime.tv_micro < Micros)    {
  2337.         CurTime.tv_micro = CurTime.tv_micro + 1000000;
  2338.         CurTime.tv_secs = CurTime.tv_secs - 1;
  2339.         }
  2340.     OldPri = SetTaskPri(MyTask,OldPri);
  2341.  
  2342.     ElTime = CurTime.tv_secs - Secs + (CurTime.tv_micro - Micros)/1000000.;
  2343.     TotTic = (double)(Time2Lo - Time1Lo);
  2344.     if (TotTic < 0.)    {
  2345.         TotTic = TotTic + (65536.*65536.);
  2346.         Time2Hi--;
  2347.         TotTic = TotTic + 655536.*65536.*(double)(Time2Hi - Time1Hi);
  2348.         }
  2349.     else    {
  2350.         TotTic = TotTic + 655536.*65536.*(double)(Time2Hi - Time1Hi);
  2351.         }
  2352.     Freq = 600*32768/ElTime;    /*About 600 cycles per pass */
  2353.     Freq = 2.1*Freq;
  2354.     Multip = Freq/BusFrq;
  2355.     IMult = (int)Multip;
  2356.     Freq = (double)IMult*BusFrq/2.;
  2357.     ClkFrq = Freq;
  2358.  
  2359. }
  2360.  
  2361.  
  2362.  
  2363. int main(void)
  2364. {
  2365. ULONG WindowBufSize;
  2366. ULONG BMAttr;
  2367. char    StrBuf[100];
  2368. int VPos,KeyCnt;
  2369.  
  2370. UBYTE KeyVal;
  2371.     SDRV =    (UBYTE *)0xbfec01;
  2372.     DDRAV =    (UBYTE *)0xbfe201;
  2373.     PDRAAV = (UBYTE *)0xbfe001;
  2374.     POTGOR = (UWORD *)0xdff016;
  2375.     PalOpt = 3;
  2376.     Pi = 2*atan(1.);
  2377.     Two = 2.;
  2378.     SaveIFF = FALSE;
  2379.     LastMax = 0;
  2380.     PowerF = 0.;
  2381.     DeltaP = 0.;
  2382.     WindowBuf = 0;
  2383.     SysFlag = SysBase -> AttnFlags;
  2384.     LibsOpen();
  2385.     MyTask = FindTask(0);
  2386.     OpenTimer();
  2387.     ClockGet();
  2388.     CPUStuff();
  2389.     Pi = 4.*atan(1.);
  2390.     TwoPi = 2.*Pi;
  2391.     PiD2 = Pi/2.;
  2392.     Power = 2;
  2393.     PowerN = 2.;
  2394.     CPU = 0;
  2395.     MaxCnt = 256;
  2396.     MaxCnt = 64;
  2397.     MltPlr = 0x80;
  2398.     WindowSet();
  2399.     if (SysFlag)    {
  2400.         SysFlag = SysBase -> AttnFlags;
  2401.         SWidth = 600;
  2402.         SHeight = 400;
  2403.         XC = SWidth/2;
  2404.         YC = SHeight/2;
  2405.  
  2406.         if (WBScreen->Width < 600) MltPlr = 0x40;
  2407.         Factor = (double)MltPlr;
  2408.         DX = 1./Factor;
  2409.         LastFactor = Factor;
  2410.         if (NumColors)    MaxCnt = NumColors;
  2411.         ScreenSet();
  2412.         WindowToFront(IntWindow);
  2413.         if (NumColors > 256) MaxCnt = 256;
  2414.         if (NumColors <= 256) {
  2415.             WindowBufSize = WBScreen->Width*WBScreen->Height;
  2416.             WindowBuf = AllocMem(WindowBufSize,MemMode);
  2417.             VPos = ShowPalette();
  2418.             VPos = VPos - 100;
  2419.             }
  2420.         else {
  2421.             WindowBufSize = 4*WBScreen->Width*WBScreen->Height;
  2422.             WindowBuf = AllocMem(WindowBufSize,MemMode);
  2423.             GreyPixels((ULONG *)WindowBuf,(ULONG)WWidth,(ULONG)WHeight);
  2424.             VPos = 16 + ShowPicPalette();
  2425.             WritePixelArray((APTR*)WindowBuf,0,0,4*WWidth,IntWindow->RPort,BLeft,BTop,WWidth,WHeight,RECTFMT_ARGB);
  2426.             VPos = WHeight - 60;
  2427.             }
  2428.         MaxCnt = 32;
  2429.         SetFont(CWRast,CWFont);
  2430.         SetAPen(CWRast,1);
  2431.         Move(CWRast,10,VPos);
  2432.         VPos = VPos + 15;
  2433.         Move(CWRast,10,VPos);
  2434.         if (NumColors <= 256)    {
  2435.             if(IntWindow->Width > 320)    {
  2436.                 sprintf(&StrBuf[0],"This display shows the %d colors of",PalSize);
  2437.                 Text(CWRast,&StrBuf[0],strlen(StrBuf));
  2438.                 VPos = VPos + 15;
  2439.                 Move(CWRast,10,VPos);
  2440.                 Text(CWRast,(STRPTR)"the palette being used for the",30);
  2441.                 VPos = VPos + 15;
  2442.                 Move(CWRast,10,VPos);
  2443.                 Text(CWRast,"Mandelbrot Images! The palette for",34);
  2444.                 VPos = VPos + 15;
  2445.                 Move(CWRast,10,VPos);
  2446.                 Text(CWRast,(STRPTR)"this screen may have changed, but will be",38);
  2447.                 VPos = VPos + 15;
  2448.                 Move(CWRast,10,VPos);
  2449.                 Text(CWRast,"restored when SMan is done!",27);
  2450.                 VPos = VPos + 15;
  2451.                 Move(CWRast,20,VPos);
  2452.                 }
  2453.                 MWBitMap = (struct BitMap *)AllocBitMap((ULONG)WBScreen->Width,WBScreen->Height,WDepth,BMF_CLEAR|BMF_DISPLAYABLE,WBScreen->RastPort.BitMap);
  2454.                 if (!MWBitMap) {
  2455.                     printf("Couldn't allocate the 1st BitMap!\n");
  2456.                     }
  2457.             InitRastPort(&MainWRast);
  2458.             MainWRast.Layer = NULL;
  2459.             MainWRast.BitMap = MWBitMap;
  2460.             Text(CWRast,(STRPTR)"Press Left Mouse Button to Continue!",36);
  2461.             OffMenu(IntWindow,0xf8c2); /* Turn off palette option*/
  2462.         }
  2463.         else    {
  2464.             PalSize = 256;
  2465.  
  2466.             if (BPP > 1) {
  2467.                 OffMenu(IntWindow,0xf860);    /* Turn off Save Image (iff). */
  2468.                 PalSize = 0x8000;
  2469.                 if (SDepth >= 16) PalSize = 0x10000;
  2470.                 }
  2471.             VPos = VPos - 32;
  2472.             Move(CWRast,20,VPos);
  2473.             SetAPen(CWRast,2);
  2474.             sprintf(&StrBuf[0],"This display above shows some of the");
  2475.             Text(CWRast,&StrBuf[0],strlen(StrBuf));
  2476.  
  2477.             VPos = VPos + 15;
  2478.             Move(CWRast,20,VPos);
  2479.             sprintf(&StrBuf[0],"nearly %d colors of the palette",PalSize);
  2480.             Text(CWRast,&StrBuf[0],strlen(StrBuf));
  2481.  
  2482.             VPos = VPos + 15;
  2483.             Move(CWRast,20,VPos);
  2484.  
  2485.             Text(CWRast,(STRPTR)"used for the Mandelbrot Images!",31);
  2486.  
  2487.             VPos = VPos + 15;
  2488.             VPos = VPos + 15;
  2489.             Move(CWRast,20,VPos);
  2490.             SetAPen(CWRast,2);
  2491.             Text(CWRast,(STRPTR)"Press Left Mouse Button to Continue!",36);
  2492.         }
  2493.  
  2494.  
  2495.         MenVal = 0;
  2496.         while ((MenVal != SELECTDOWN)&&(MenVal != 0xf8c0)) {
  2497.              CheckIntMsg();
  2498.             if (IMClass == CLOSEWINDOW) MenVal = 0xf8C0;
  2499.              Delay(1);
  2500.             }
  2501.         XWidth = WWidth;
  2502.         XHeight = WHeight;
  2503.         HWidth = XC;
  2504.         XCenter = XC;
  2505.         HHeight = YC;
  2506.         YCenter = YC;
  2507.         LastX = XCenter;
  2508.         LastY = YCenter;
  2509.         WriteStuff();
  2510.         ActivateWindow(InfoWindow);
  2511.         MenVal = 0xf801;
  2512.         while (MenVal != 0xf8c0)    {
  2513.             FullSurface();
  2514.             while ((!MenVal) && (!IMClass))    {
  2515.                 Status();
  2516.                 }
  2517.             }
  2518.         }
  2519.     if (((SysFlag & AFF_68881)||(SysFlag & AFF_68882))&&((SysFlag & AFF_68020)||(SysFlag & AFF_68030))||(SysFlag & AFF_68040))    {
  2520.         BPP = BPP;
  2521.         }
  2522.     else {
  2523.         ErrorDisplay();
  2524.         }
  2525.     if (WBScreen->RastPort.BitMap->Depth >= 5) {
  2526.         WBScreen->ViewPort.ColorMap->ColorTable = OldColorTable;
  2527.         if (NumColors <= 256) RestoreOrigColors();
  2528.     }
  2529.     if (!WindowBuf) {
  2530.         if (MWBitMap) FreeBitMap(TmpBitMap);
  2531.         }
  2532.     Delay(25);
  2533.  
  2534.     if (NewColorTable)    {
  2535.         FreeMem(NewColorTable,TableSize);
  2536.         NewColorTable = 0;
  2537.         }
  2538.     if (WindowBuf) {
  2539.         FreeMem(WindowBuf,WindowBufSize);
  2540.         WindowBuf = 0;
  2541.         }
  2542.     ScreensClose();
  2543.     CloseTimer();
  2544.     LibsClose();
  2545.     return(0);
  2546. }
  2547.